Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, Swift, BASIC, and whatever else I happen to feel like hacking at.

Automator problems with custom Python

Jerry Stratton, May 21, 2007

I thought I’d implement this simple drag-and-drop PDF combiner at the office today, only to discover that it didn’t work. I made a simpler one: just the two steps “combine PDF” and “open in preview”. I noticed that the files were being created but were empty. In the console app I found the following error:

[toggle code]

  • Traceback (most recent call last):
    • File "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py", line 23, in ?
      • from CoreGraphics import *
  • ImportError: No module named CoreGraphics

It was interesting to see that at least some Automator functionality is programmed in Python.

My problem was that, at the office, I updated Python from the 2.3 that comes with Mac OS X 10.4 to 2.4, and then I made 2.4 the default (linked /usr/bin/python to /usr/local/bin/python2.4). However, the way Python works is that libraries are installed on a per-version basis. So 2.4 had no idea where to import the core graphics library.

I switched the default Python back to 2.3 and the Automator app began working as expected.

In response to Combining multiple PDF files into a single file: Automator allows you to combine multiple PDF files into a single file.