Get iCal event info via Applescript for repeating events
Nov 30, '09 07:30:01AM • Contributed by: Andrew J Freyer
Nov 30, '09 07:30:01AM • Contributed by: Andrew J Freyer
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:
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:
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.
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
else
return missing value
end if
end tell
end repeat
end tellset theNextOrCurrentEvent to (do shell script "/usr/local/bin/icalbuddy -ic \"CalendarName\" -eep \"*\" -nc -b \"\" -n -li 1 eventsToday")
•
[8,806 views]
