Get Facebook Birthdays

Mixin.com offer a Facebook app that creates a calendar file of your Facebook friends' birthdays that you can subscribe to in iCal. Take a look at www.fbcal.com. I wrote the following Applescript to copy your Facebook friends' birthdays into Address Book so that Dates to iCal could have access to these dates.

To do this, you will need to set up the fbCal calendar before my script will do anything. This is a pretty simple process involving allowing the app access to your account in Facebook. Once you have this set up, run my Get Facebook Birthdays script (you can download Get Facebook Birthdays saved as an application here). The script will add all the birthdays to people in Address Book, searching for similarly named people, and checking whether the date should be added to that person or a new one. All new people are added to a group 'fbCal Birthdays'.

This was written in response to this question in Apple Discussions.

I'd love to hear if you have any comments or improvements to make to this script.

  1. -- Get Facebook Birthdays --
  2. -- John Maisey -- 26 Feb 2011 -- nhoj.co.uk -- v1.0
  3. -- Copies events created by the Facebook app at fbcal.com to your Address Book.
  4.  
  5. set defaultTitle to "Get Facebook Birthdays - nhoj.co.uk"
  6.  
  7. tell application "iCal"
  8. activate
  9. set myResult to button returned of (display dialog "Copy Facebook birthdays from iCal to Address Book." & return & "This script requires the 'fdCal Birthdays' calendar that can be created by following the instructions at fbcal.com." with title defaultTitle buttons {"Visit fbcal.com", "Cancel", "Copy birthdays"} default button 3)
  10. if myResult is equal to "Visit fbcal.com" then
  11. tell application "System Events" to open location "http://www.fbcal.com"
  12. return
  13. end if
  14.  
  15. try
  16. set sourceCal to calendar "fdCal Birthdays"
  17. on error theErr
  18. display dialog theErr
  19. return
  20. end try
  21. set myEvents to events of sourceCal
  22. tell application "Address Book" to if (name of groups does not contain "fdCal Birthdays") then (make new group with properties {name:"fdCal Birthdays"})
  23.  
  24. repeat with myFBBirthday in myEvents
  25.  
  26. set theName to item 1 of my cjmTIDs(summary of myFBBirthday, "'s ")
  27. set firstName to (word 1 of theName)
  28. set lastName to (word -1 of theName)
  29. set bDate to (start date of myFBBirthday)
  30. set makeNewPerson to false
  31.  
  32. tell application "Address Book"
  33. set myPeople to (people whose first name contains firstName and last name contains lastName)
  34. if (count of myPeople) is equal to 0 then
  35. set makeNewPerson to true
  36. else
  37. set myList to {}
  38. repeat with thisEntryCount from 1 to (count of myPeople)
  39. set end of myList to (thisEntryCount as text) & ". " & (name of (item thisEntryCount of myPeople))
  40. end repeat
  41. if (count of myPeople) is equal to 1 then
  42. set myPreamble to "There is already an entry for '"
  43. set myPostamble to "this person?"
  44. else
  45. set myPreamble to "There are already entries for '"
  46. set myPostamble to "one of these?"
  47. end if
  48. activate
  49. set myResult to choose from list myList with prompt myPreamble & theName & "' in your Address Book. Would you like the birthday added to " & myPostamble with title defaultTitle OK button name "Add to person" cancel button name "New person" default items {item 1 of myList} with empty selection allowed without multiple selections allowed
  50. if myResult is equal to false then
  51. set makeNewPerson to true
  52. else
  53. set myABPerson to item (word 1 of (item 1 of myResult)) of myPeople
  54. end if
  55. end if
  56. if makeNewPerson then
  57. set myABPerson to (make new person with properties {first name:firstName, last name:lastName, birth date:bDate})
  58. add myABPerson to group "fdCal Birthdays"
  59. end if
  60. set birth date of myABPerson to bDate
  61. end tell
  62.  
  63. end repeat
  64.  
  65. tell application "Address Book"
  66. save
  67. set myResult to button returned of (display dialog "Transfer complete." with title defaultTitle buttons {"Visit nhoj.co.uk", "Done"} default button 2)
  68. if myResult is equal to "Visit nhoj.co.uk" then tell application "System Events" to open location "http://www.nhoj.co.uk"
  69. end tell
  70.  
  71. end tell
  72.  
  73. on cjmTIDs(theText, theDelim)
  74. set my text item delimiters to theDelim
  75. set myList to text items of theText
  76. set my text item delimiters to {""}
  77. return myList
  78. end cjmTIDs

Comments

i have been looking for a script to do the exact opposite i did that a while back and regret it i want to cleen my ical but need get rid of all the birthdays. if you could help me i would greatly appritiacte it.

Hi John,

Thanks for such a great app!
Unfortunately it doesn't work for me. I'm not so great at tech stuff, so it may be an easy fix.

I don't have fbCal, but FB allows you to export a birthday calender directly to FB (click on events, birthdays, then the magnifying glass and export..)
This creates a brithday calendar in iCal. Your app was unable to take the birthdays from there, and put in in my address book. I don't think fbCal exists anymore (perhaps for this reason).
Would it be a simple change in the script to have the birthdays taken from the Birthday Calender?

I tryied changing the name of the calender to fbCal, but it didn't work..

Many Thanks,

Big Fan

Aaron