Scripting iCal with Python

I’m too cheap to pay Apple for .Mac. Besides, I want to synchronise my calendar with more devices than they support. Specifically, I’d like to be able to use Sunfire to edit my shared calendars, as well as my phone and my Mac. Currently I keep my calendars on the excellent iCalX.com.

The best solution seems to be to develop my own synchronisation tool, to ‘enhance’ Apple’s offering. This entry contains a few building blocks that I’ll be needing.

Information on using Python to script iCal is at stompstompstomp.com. This works well. iCal is scriptable, even though the interface isn’t very object orientated. There is a better interface builder called AppScript, but I’m put off by the fact that it depends upon a number of other packages.

One minor problem is in date conversions. Apple’s Open Scripting Architecture (OSA) epoch starts on the 1st January, 1904. Python uses the Unix epoch that starts in 1970. Here’s a tiny module that helps with the conversion:

"""Apple's Open Scripting Architecture stores dates
    as seconds since 1-Jan-1904. This is 2082844800
    seconds before the Unix epoch.
"""

_offset=2082844800L

def to_osa_date(unix_date):
  return long(unix_date) + _offset

def from_osa_date(osa_date):
  return osa_date - _offset

More on this later, I hope.

Update 2006/05/30

In order to talk with iCal, python needs access to the window manager. So I need to run python as pythonw. Unfortunately that always starts an icon in the Dock, which won’t do if this program is to run in the background and constantly sync my calendars.

The solution is to run py2app on the script, and then set the new app’s LSUIElement element to 1.

Comment · Comments Feed · TrackBack

  1. johnjones said,

    10 January, 2006 @ 03:47

    what would be nice…

    sync your calendars with a online repository that you had control over maybe something like a blog…

    you could maybe use syncml

    sync4j open server built with java and C++ toolkit http://www.funambol.com/opensource/

    A python toolkit has been developed as part of erp5 project and is used by the french gov you will have to goole for the packages also a while ago an IBM writer wrote this http://usefulinc.com/software/syncml

    regards

    John Jones

  2. has said,

    21 January, 2006 @ 21:30

    > There is a better interface builder called AppScript, but I’m put off by the fact that it depends upon a number of other packages.

    There’s an all-in-one binary installer available at:

    http://freespace.virgin.net/hamish.sanderson/appscript.html#appscriptinstaller

    HTH

  3. parambyte said,

    1 April, 2006 @ 10:49

    it would be nice if there were some open source solution that let you sync your iCal with your personal website (something like phpicalendar) and then sync THAT with X number of mobile devices, throuh maybe SyncML. I think some solutions just need to be threaded together (like phpicalendar and Sync4j) if its not been done already

Leave a Comment

Sponsors