Created
August 29, 2009 22:02
-
-
Save simonjefford/177692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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