Simon Jefford

thisweek - a useful script for GeekTool

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.

example script output

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.

Opening up Cocoa classes with Ruby == awesome

    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.

Objective-C selectors don’t translate well (in RubyCocoa anyway)

    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

blog comments powered by Disqus