I’ve been using GeekTool for a while now to put useful information onto my desktop. Probably the most useful panel on there comes from my “thisweek” script. This script shows the events, across all the calendars I have in iCal that are coming up in the next 7 days.

The inspiration (and chunks of the code) came from iphonelogd - a script for putting iPhone call log information into iCal. iphonelogd, and my script, use RubyCocoa along with the Leopard Calendar Store API to access calendar data. The full script is available as a Gist. There are a couple of reasonably interesting things I learned along the way.
class CalEvent
def formatted
time_part = (self.isAllDay == 1) ? " '(All Day)'" : " 'at' HH:mm";
format = "EEEE#{time_part}"
"(#{self.calendar.title}) #{self.title} - #{self.startDate.formatted(format)}"
end
end
Once I have a list of calendar events (as represented by instances of CalEvent), I can use #formatted to get a nice textual description of the event.
eventPred = CalCalendarStore.eventPredicateWithStartDate_endDate_calendars_(NSDate.date,
NSDate.dateWithNaturalLanguageString("next week"), cals)
Enough said! That said, this would of course be much nicer in MacRuby.
eventPred = CalCalendarStore.eventPredicateWithStartDate NSDate.date,
endDate:NSDate.dateWithNaturalLanguageString("next"),
calendars:cals
29 Aug 2009