Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Get iCal event info via Applescript for repeating events Apps
Anyone who has ever tried to retrieve the current agenda in iCal via AppleScript realizes how impossible it is. The problem is that iCal's AppleScript keywords seem keyed for adding information to events, not extracting information from those events.

Anyway, the main problem for me was extracting a current event title for use in an AppleScript. Retrieving the title information for a single event was simple. The following code is an example I found with a quick Google search:
tell application "iCal"
  set d to the current date
  repeat with c in every calendar
    tell c
      if exists event 1 then
        set e to (get every event where ((its start date ≤ d) and (its end date ≥ d)))
        if (e is not {}) then return first item of e
        return missing value
      end if
    end tell
  end repeat
end tell
However, because of a bug in iCal, getting current-day information from a repeating event is impossible (I think) from AppleScript itself. My solution is to use the iCalBuddy shell script of GeekTool fame. With that script installed, here's the solution:
set theNextOrCurrentEvent to (do shell script "/usr/local/bin/icalbuddy -ic \"CalendarName\" -eep \"*\" -nc -b \"\" -n -li 1 eventsToday")
This single line will return the summary (title) of the next or current iCal Event in calendar CalendarName, regardless of whether the event is repeating or not.
  • Currently 2.47 / 5
  You rated: 3 / 5 (15 votes cast)

Get iCal event info via Applescript for repeating events | 1 comments | Create New Account
Click here to return to the 'Get iCal event info via Applescript for repeating events' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Get iCal event info via Applescript for repeating events
Authored by: scooby509 on Nov 30, '09 04:18:07PM
I've written a script that does this in Python, parsing the iCal file directly. Alas, at the moment, it's a little hard to configure everything to actually try it out, but it's probably not too hard if you use MacPorts already.

What are you trying to get out of iCal? Right now, I can parse pretty much every calendar and step through all the events and such stored in them, including recurring events.

[ Reply to This | # ]