Last active
September 25, 2015 19:47
-
-
Save mikz/974864 to your computer and use it in GitHub Desktop.
iCal geeklet from: http://www.macosxtips.co.uk/geeklets/productivity/fully-customizable-ical-events-list-1/
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/env macruby | |
# encoding: utf-8 | |
CALENDARS = ['Michal Cichra', 'Calendar'] # Set names of calendars to show | |
before = 3 # days to show before today | |
after = 10 # days to show after today | |
today = 'dnes' | |
## no config from here | |
require 'date' | |
class Date | |
MONTHNAMES = [nil] + %w{ledna února března dubna května června července srpna září října listopadu prosince} | |
DAYNAMES = %w{neděle pondělí úterý středa čtvrtek pátek sobota} | |
end | |
class Time | |
alias :strftime_nolocale :strftime | |
def strftime(format) | |
format = format.dup | |
format.gsub!(/%a/, Date::ABBR_DAYNAMES[self.wday]) | |
format.gsub!(/%A/, Date::DAYNAMES[self.wday]) | |
format.gsub!(/%b/, Date::ABBR_MONTHNAMES[self.mon]) | |
format.gsub!(/%B/, Date::MONTHNAMES[self.mon]) | |
self.strftime_nolocale(format) | |
end | |
def midnight? | |
min == 0 and sec == 0 and hour == 0 | |
end | |
def to_date | |
::Date.new(year, month, day) | |
end unless method_defined?(:to_date) | |
end | |
framework 'calendarstore' | |
range = (Date.today - before)..(Date.today + after) | |
predicate = CalCalendarStore.eventPredicateWithStartDate(NSDate.dateWithNaturalLanguageString(range.begin.to_s), | |
endDate:NSDate.dateWithNaturalLanguageString(range.end.to_s), | |
calendars:CalCalendarStore.defaultCalendarStore.calendars ) | |
events = {} | |
CalCalendarStore.defaultCalendarStore.eventsWithPredicate(predicate).each do |event| | |
next unless CALENDARS.include? event.calendar.title | |
event.isAllDay = true if event.startDate.midnight? && event.endDate.midnight? | |
event.endDate -= 1 if event.isAllDay && event.endDate.midnight? | |
dates = ((event.startDate.to_date)..(event.endDate.to_date)).step(1).to_a | |
dates.each do |date| | |
events[date] ||= [] | |
events[date] << event | |
end | |
end | |
events.each do |date, events| | |
print date.strftime("● %A %d. %B").uppercaseString | |
print " (#{today})" if date == Date.today | |
puts | |
events.each do |event| | |
started_at = Time.at(event.startDate.timeIntervalSince1970) | |
ends_at = Time.at(event.endDate.timeIntervalSince1970) | |
#Display an arrow if event has started | |
print " ✓" if ends_at < Time.now | |
#Display a star if event is current | |
print " ☆" if started_at < Time.now && Time.now < ends_at | |
print "\t" + (event.isAllDay ? "" : started_at.strftime("%R") + "-" + ends_at.strftime("%R") + " - ") | |
print event.title | |
print " @ #{event.location.strip.gsub("\n", ", ")}" if event.location and event.location != "" | |
print "\n" | |
end | |
puts # new line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment