Friday, March 20, 2009

ircontroller - super simple module for using the MacBook remote from Python

In the event you have a MacBook, and would like to write a Python program that you can control via the nice little remote controllers that come with the MacBook, you might find ircontroller handy.

It also gave me a chance to put something up on Google code. I had worked with SourceForge way back in the day, and being a rather Google-centric guy of late, Google code seemed like the place to go.

You'd think there would already be a module like this about, but in my searching the best thing I could find was the code for the iremoted 'daemon'. Converting it to a Python extension was relatively straightforward. The only part that caused pain was determining how to get distutils to link in the IOKit and Carbon frameworks. I found a blog post by somebody who'd already dealt with that pain, so that was the end of that.

Anyhow the file is super simple, and (once you know the quirks) way preferable to mucking about with a makefile.
from distutils.core import setup, Extension
ext_modules=[Extension('ircontroller', ['ircontroller.c'],
extra_link_args=['-framework', 'IOKit', '-framework','Carbon'])])

Needless to say, this won't build on Windows (or Linux either, or Plan 9, or Solaris, or whatever).

Here ya go.