By the standards of some 1337ists, I am a child of a lesser god: I confess to using Windows. If you share this disdain, then avert your eyes.
However, if you use Outlook, and care to see how to use Ruby to add appointments to the Outlook calender, then read on.
I've gradually been migrating off of Microsoft products, but as a calender app Outlook 2000 serves me better than the alternatives I've examined. (I expect that in some possible future I may move to Sunbird, but it isn't quite there yet for me.)
I mostly use Outlook to remind me to do basic stuff, such as move the trash bin to the curb for pick-up, or set the VCR to tape House. (Analog rules!) Adding items can be tedious, though, what with assorted selecting and clicking and saving. What I really wanted was a way to add stuff from the command line (which I hear is how most Mac users do things, actually).
After a bit of poking around I found assorted example of scripting Outlook via the COM interface. I swiped some moves and came up with this class:
require 'win32ole'
require 'date'
class Outlook
OLFolderCalendar = 9
OLAppointmentItem = 1
OLFree = 0
OLTentative = 1
OLBusy = 2
SEC = 1
MIN = 60 * SEC
HOUR = MIN * 60
def initialize( busy_default = Outlook::OLBusy )
@ol = WIN32OLE.new( "Outlook.Application" )
@busy_default = busy_default
end
def add_appointment( opts )
opts[ :busy_status ] ||= @busy_default
ol_appt = @ol.CreateItem( OLAppointmentItem )
ol_appt.Start = opts[ :start ]
ol_appt.End = opts[ :end ]
ol_appt.Subject = opts[ :subject ]
ol_appt.Location = opts[ :location ]
ol_appt.Body = opts[ :body ]
ol_appt.BusyStatus = opts[ :busy_status ]
ol_appt.ReminderSet = opts[ :set_reminder? ]
ol_appt.ReminderMinutesBeforeStart = opts[ :reminder_minutes ]
ol_appt.Save
end
end
if __FILE__ == $0
ol = Outlook.new
start_time = Time.local( 2005, 5, 27, 14, 0, 0 )
end_time = start_time + ( 120 * Outlook::MIN )
ol.add_appointment :start => start_time,
:end => end_time ,
:subject => 'Testing Ruby!',
:location => "Flatland",
:body => 'Just testing stuff',
:set_reminder? => true,
:reminder_minutes => 120
end
Season to taste.
Now writing small scripts that grab ARGV and add calender items is simpler than clicking a one-button mouse.
Proof left as an exercise for the reader.
Read: Outlook Appointments with Ruby