I’ve used 3rd party software to create events with alarms for Address Book birthdays. None of the dozen or so solutions I tried had an option to include the Note field data in the new events. So I either need a solution that does this, or one that will get each Note from Address Book and add it to each new event. It seems like there should be an Applescript that will handle the 2nd option, but I can’t seem to make it work.
Hi. Welcome to MacScripter.
You don’t say if you’re using iCal’s built-in “Birthdays” calendar, which automatically shows any birthdays entered in Address Book, or whether you’re using one of your own.
With the built-in calendar, it’s probably easiest to get the ‘URL’ of each event, derive the ‘ID’ of the ‘person’ in Address Book from that, get the person’s ‘note’, and set the event’s ‘description’ to the result. Although the calendar’s not supposed to be editable in iCal itself, it does seem to be possible (in Snow Leopard) to edit its events’ descriptions by script:
tell application "iCal" to set birthdayEvents to events of (first calendar where it is not writable and name is "Birthdays")
repeat with thisEvent in birthdayEvents
tell application "iCal" to set eventURL to thisEvent's url
if (eventURL is not missing value) then
set personID to text 15 thru -1 of eventURL
tell application "Address Book" to set theNote to note of person id personID
if (theNote is missing value) then set theNote to ""
tell application "iCal" to set thisEvent's description to theNote
end if
end repeat
Thanks for your assistance, Nigel. I am not using Address Book’s built-in Birthday calendar, since it doesn’t show the contact’s Notes/Description on the calendar, and it doesn’t support alarms. (I am using iCal 3.0.8 on Leopard.) As I mentioned in my first post, I used a 3rd-party utility to create standard iCal events with multiple alarms in a new calendar, Birthdays2. I believe all I need to change is the first line, yes?
tell application “iCal” to set birthdayEvents to events of (calendar where name is “Birthdays2”)
repeat with thisEvent in birthdayEvents
tell application “iCal” to set eventURL to thisEvent’s url
if (eventURL is not missing value) then
set personID to text 15 thru -1 of eventURL
tell application "Address Book" to set theNote to note of person id personID
if (theNote is missing value) then set theNote to ""
tell application "iCal" to set thisEvent's description to theNote
end if
end repeat
Hi.
If your third-party software sets the URL of each event to a “Show in Address Book.” link, you do probably only need to change the first line of the script:
tell application "iCal" to set birthdayEvents to events of calendar "Birthdays2"
-- etc.
If not, you’ll need a different method to match events to people. I’m thinking about it at the moment. Are the event summaries just the people’s names, or are they something like “Fred Bloggs’s birthday”?
OK. This works for me:
-- Get parallel lists of the names, birth dates, and notes of all the people in Address Book.
tell application "Address Book" to set {theNames, birthDates, theNotes} to {name, birth date, note} of people
-- Get parallel lists of the summaries, start dates, and IDs of all the events in the birthday calendar.
tell application "iCal" to set {theSummaries, startDates, eventIDs} to {summary, start date, uid} of events of calendar "Birthdays2"
set eventCount to (count theSummaries)
-- Work through the birth dates, only looking further when a "date" isn't 'missing value'.
repeat with i from 1 to (count birthDates)
set thisBirthDate to item i of birthDates
if (thisBirthDate is not missing value) then
-- Set the birth date's time to a set value and get the corresponding note and name.
set thisBirthDate's time to 0
set thisNote to item i of theNotes
if (thisNote is missing value) then set thisNote to ""
set thisName to item i of theNames
-- Work through the event summaries to find one containing the name.
repeat with j from 1 to eventCount
if (item j of theSummaries begins with thisName) then
-- If there is one and the corresponding start date matches the birth date, set the event's description to the note.
set thisStartDate to item j of startDates
set thisStartDate's time to 0
if (thisBirthDate is thisStartDate) then
tell application "iCal" to set description of event id (item j of eventIDs) of calendar "Birthdays2" to thisNote
exit repeat
end if
end if
end repeat
end if
end repeat
Hi Nigel. My third party software does set the URL of each event as you describe, so the 1st line change worked nicely. Thank you again!
(I did give the 2nd script a try, and it ran without error, but never produced the desired results. The very brief runtime suggested to me that it wasn’t repeating.)