[Pythonmac-SIG] scripting iCal
has
hengist.podd at virgin.net
Mon Nov 29 01:56:19 CET 2004
David Reed wrote:
>I'm now trying to write a script to just grab the events for the
>current date. I could pull all the events and check their start date,
>but figure there is probably an easier way.
Use appscript: http://freespace.virgin.net/hamish.sanderson/appscript.html
Example:
#!/usr/local/bin/pythonw
from appscript import *
from datetime import date, timedelta
today = date.today()
tomorrow = today + timedelta(1)
# To get a list of today's events in calendar 1:
print app('ical.app').calendars[1].events.filter((its.start_date >=
today).AND(its.start_date < tomorrow)).get()
# To get names and descriptions of today's events in 'Home' calendar:
ref = app('ical.app').calendars.filter(its.title ==
'Home').events.filter((its.start_date >= today).AND(its.start_date <
tomorrow))
print zip(ref.summary.get(), ref.description.get())
Notes:
- iCal's scripting support isn't too great - like most of Apple's
iApps. Hence stupid crap like using filters to get calendars by
title: the doofuses that defined its Apple event object model used
'title' instead of 'name' for no obvious reason, which prevents you
from just using calendars['Home'] as you would in most apps.
- For asking advice on scripting specific applications, you might
want to subscribe to the macscrpt mailing list:
<http://listserv.dartmouth.edu/scripts/wa.exe?A0=macscrpt&D=1&H=0&O=D&T=1>
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
More information about the Pythonmac-SIG
mailing list