Address Book Custom Dates to iCal
Had created this script since couple of days back I missed a friends Wedding Anniversary…
Anyways, this is the first version of the script. Plan to change it to update only changed contacts.
But it works for me now…
Check it out…
— ====== AppleScript Start ====== —
— Variables —
set iCalCalendar to “Address Book Dates”
set DateList to {}
set CalendarFound to false
— Logic —
tell application “iCal”
if not (exists calendar iCalCalendar) then
display dialog “Please create new Calendar called
'” & iCalCalendar & "’ with Info: Ignore alerts and Events affect availability off.
Then run this script again."
else
set CalendarFound to true
end if
end tell
if CalendarFound then
tell application “Address Book”
activate
repeat with this_person in every person
if (custom dates of this_person is not missing value) then
repeat with this_date in custom dates of this_person
#set NewRecord to {name:label of thisperson & "," & tag:label of this_date & "," & value:value of this_date}
set EntryName to missing value
if first name of this_person is not missing value and last name of this_person is not missing value then
set EntryName to first name of this_person & " " & last name of this_person
else
set EntryName to name of this_person
end if
set end of DateList to {PersonId:id of this_person, PersonName:EntryName, DateType:label of this_date, DateValue:value of this_date}
end repeat
end if
end repeat
end tell
tell application "iCal"
activate
reload calendars
tell calendar iCalCalendar
set its color to {3598, 24929, 47545}
set description to "via Address Book Dates to iCal.scpt"
if (count of every event) > 0 then
set AllEvents to every event
repeat with current_event in AllEvents
delete current_event
end repeat
end if
repeat with dl in DateList
set PersonId to PersonId of dl
set PersonName to PersonName of dl
set DateType to DateType of dl
set DateValue to DateValue of dl
set DateStr to missing value --date string of (DateValue as date)
if (year of (DateValue as date)) = 1604 or (year of (DateValue as date)) = 1900 then
set DateStr to day of (DateValue as date) & " " & month of (DateValue as date)
else
set DateStr to day of (DateValue as date) & " " & month of (DateValue as date) & " " & year of (DateValue as date)
end if
set EventTitle to missing value
if DateType = "anniversary" then
set DateType to "Anniversary"
set EventTitle to "â• " & PersonName & "'s " & DateType
else if DateType = "engagement" then
set DateType to "Engagement"
set EventTitle to "â " & PersonName & "'s " & DateType
else
set EventTitle to "★ " & PersonName & "'s " & DateType
end if
set Desc to PersonName & "'s " & DateType & " (" & DateStr & ")"
make new event with properties {description:Desc, url:"addressbook://" & PersonId, allday event:true, start date:DateValue, end date:DateValue, summary:EventTitle, recurrence:"FREQ=YEARLY;INTERVAL=1"}
end repeat
end tell
end tell
end if
— ====== AppleScript End ====== —