New iCal calendar assignment script
September 26, 2009 at 6:31 PM by Dr. Drang
For years now, I’ve been using iCal Exchange to share calendars between my venerable iBook G4 and my office iMac. The iMac contains the canonical versions of my calendars and publishes them at iCal Exchange, from which the iBook gets updated via subscription. Often, though, it’s more convenient if the flow of information goes in the opposite direction, so I have have one calendar—called from-ibook—that’s published on the iBook and subscribed to by the iMac. That calendar is for temporary use only. I add events to it when I don’t expect to be in the office for a while; when I do get back to the office, I move all the from-ibook events to their proper calendar—usually via a script.
This certainly isn’t as smooth as a MobileMe account would be, but it doesn’t cost $99 a year, either. I suppose I should move to a Google Calendar solution, but I’m used to this setup and it’s always worked well for me. Until this week, that is, when I first tried to run the reassignment script1 under Snow Leopard. Running it generated errors, and I had to do a small rewrite.
Here’s the new script:
1: tell application "iCal"
2: set ibook to every event in calendar "from-ibook"
3: repeat with i in ibook
4: set summ to summary of i
5: set sdate to start date of i
6: set edate to end date of i
7: set aday to allday event of i
8: if location of i is missing value then
9: set loc to ""
10: else
11: set loc to location of i
12: end if
13: if description of i is missing value then
14: set desc to ""
15: else
16: set desc to description of i
17: end if
18: set sday to short date string of sdate
19: display dialog ("Move " & quote & summ & quote & " on " & sday & " to:") buttons ["Home", "Work", "Neither"] default button 1
20: if button returned of result = "Home" then
21: make new event at end of events of calendar "home" with properties {start date:sdate, end date:edate, allday event:aday, summary:summ, description:desc, location:loc}
22: delete i
23: else if button returned of result = "Work" then
24: make new event at end of events of calendar "work" with properties {start date:sdate, end date:edate, allday event:aday, summary:summ, description:desc, location:loc}
25: delete i
26: end if
27: end repeat
28: reload calendars
29: end tell
Basically, it runs through all the events in the from-ibook calendar and asks me which calendar, home or work, I want to assign them to. It then creates new events in the appropriate calendars and deletes the old ones in from-ibook.
Before Snow Leopard, Lines 6–17 were unnecessary, and Lines 21 and 24 looked like this:
make new event at end of events of calendar "home" with data i
which was a hell of a lot more succinct. After Snow Leopard, that line generated an error and made the script fail. I don’t know whether the change is due to a change in AppleScript or a change in iCal; I’m just glad to have it working again.
Maybe I should look into syncing with Google Calendar.
-
Apparently, I never wrote a post about the original version of the script. It was, however, the model for this script, which did the same thing for events entered on the iPhone back when the iPhone’s calendar was more primitive. ↩