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.
-- John Maisey -- 26 Feb 2011 -- nhoj.co.uk -- v1.0
-- Copies events created by the Facebook app at fbcal.com to your Address Book.
set defaultTitle to "Get Facebook Birthdays - nhoj.co.uk"
tell application "iCal"
activate
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)
if myResult is equal to "Visit fbcal.com" then
tell application "System Events" to open location "http://www.fbcal.com"
return
end if
try
set sourceCal to calendar "fdCal Birthdays"
on error theErr
display dialog theErr
return
end try
set myEvents to events of sourceCal
tell application "Address Book" to if (name of groups does not contain "fdCal Birthdays") then (make new group with properties {name:"fdCal Birthdays"})
repeat with myFBBirthday in myEvents
set theName to item 1 of my cjmTIDs(summary of myFBBirthday, "'s ")
set firstName to (word 1 of theName)
set lastName to (word -1 of theName)
set bDate to (start date of myFBBirthday)
set makeNewPerson to false
tell application "Address Book"
set myPeople to (people whose first name contains firstName and last name contains lastName)
if (count of myPeople) is equal to 0 then
set makeNewPerson to true
else
set myList to {}
repeat with thisEntryCount from 1 to (count of myPeople)
set end of myList to (thisEntryCount as text) & ". " & (name of (item thisEntryCount of myPeople))
end repeat
if (count of myPeople) is equal to 1 then
set myPreamble to "There is already an entry for '"
set myPostamble to "this person?"
else
set myPreamble to "There are already entries for '"
set myPostamble to "one of these?"
end if
activate
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
if myResult is equal to false then
set makeNewPerson to true
else
set myABPerson to item (word 1 of (item 1 of myResult)) of myPeople
end if
end if
if makeNewPerson then
set myABPerson to (make new person with properties {first name:firstName, last name:lastName, birth date:bDate})
add myABPerson to group "fdCal Birthdays"
end if
set birth date of myABPerson to bDate
end tell
end repeat
tell application "Address Book"
save
set myResult to button returned of (display dialog "Transfer complete." with title defaultTitle buttons {"Visit nhoj.co.uk", "Done"} default button 2)
if myResult is equal to "Visit nhoj.co.uk" then tell application "System Events" to open location "http://www.nhoj.co.uk"
end tell
end tell
on cjmTIDs(theText, theDelim)
set my text item delimiters to theDelim
set myList to text items of theText
set my text item delimiters to {""}
return myList
end cjmTIDs
Comments
aj (not verified)
24 January, 2012 - 04:29
Permalink
i have been looking for a
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.
Aaron G (not verified)
18 May, 2012 - 03:35
Permalink
Hi John, Thanks for such a
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
Pages