Skip to content

Instantly share code, notes, and snippets.

@simonjefford
Created August 29, 2009 22:02
Show Gist options
  • Save simonjefford/177692 to your computer and use it in GitHub Desktop.
Save simonjefford/177692 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'osx/cocoa'
include OSX
NSBundle.bundleWithPath("/System/Library/Frameworks/CalendarStore.framework").load
ns_import :CalendarStore
class NSDate
def formatted(format)
formatter = NSDateFormatter.new
formatter.dateFormat = format
formatter.stringFromDate(self)
end
end
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
store = CalCalendarStore.defaultCalendarStore()
# TODO - read ignored calendars from a dotfile
cals = store.calendars.reject {|cal| cal.title == "Library Loans"}
eventPred = CalCalendarStore.eventPredicateWithStartDate_endDate_calendars_(NSDate.date,
NSDate.dateWithNaturalLanguageString("next week"), cals)
events = store.eventsWithPredicate(eventPred)
puts "This Week"
puts
events.each do |event|
puts event.formatted
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment