Keynote tools:

a collection of command line tools for Mac Keynote presentations

This is a set of command-line tools (written in Python) for manipulating Keynote format files, as generated by the presentation program that is part of Apple’s iWork package.

A common and annoying problem is that when images are dragged and dropped into Keynote they are stored in Apple’s PICT format.  This is fine on a Mac, but when you export the presentation to Powerpoint and then try to display it on a PC you get the dreaded error message “QuickTime and a decompressor are needed to see this picture”.  The same problem occurs if you drag and drop images into Mac Powerpoint and then play that file on  a PC.  The usual solutions are to:

  1. not drag and drop files, always use File/Import

  2. save such problematic pictures and then reinsert them

both of which are limiting and/or tedious.  Maybe Apple and Microsoft will fix this in the future but for now...

The root cause of the problem are the PICT format files embedded in the presentation, and PICT is an unusual file format that is part of QuickTime.  Powerpoint uses a complex binary format file so that makes life difficult to figure out what is going on.  However for Keynote things are much better, a keynote presentation is an application bundle, a directory that contains all the media items as well as a zipped XML format file.  This is easy to parse and process, and the images are simple files within the bundle where they can be easily manipulated.

To see what’s there in the bundle:

The keynote file is either specified as a full path with the .key extension, or as the name without the .key extension, in which case it is looked for in the path specified by the keynotePath variable in the program.

However we can do more than just list then elements, we can also change them.  To solve our problem with the PICT files we use

This finds all user media that is of PICT format, converts the image file to JPEG format, and modifies the XML accordingly.  It’s somewhat major surgery so it would be prudent to back up first.  The program is also a bit chatty and let’s you know what it’s up to.

Since keynote stores copies of movies rather than links it can quickly eat up your disk space.  I know there is an option to not store copies but it used to give me grief.

This tool will look for all movies in the presentation and if they are found within the file system based at  a symbolic link will be created.  Movies are looked for in a path specified by the variable moviePath

These tools mess with the innards of your Keynote presentation, so make a copy before you start!


Download the compressed tar file  keynote.tgz

About Keynote files

A Keynote (iWork 08) presentations is an application bundle, a directory that contains all the media files and an XML format file index.apxl.gz which defines the layout using this schema.   All media is referenced in an sf:data element, with various other attributes.  So mostly its a matter of finding these elements and perhaps rewriting them.

The media items referred to in the XML file are either:

  1. added by the user, and can be of any kind, eg. .jpg, .png, .gif, .tiff, .mov etc

  2. part of the theme with a name like theme.kth/foo

  3. a thumbnail image with a name like thumbs/foo.png

We restrict our interest to just the first type.

Converting image formats

This should have been the easy part!  Just use convert from ImageMagick.  If only it were that simple, and it’s things like this that make the Mac such a frustrating platform for Linux/Unix people.  In brief the things I tried:

  1. *ImageMagick convert, just doesn’t work from fink or darwinports.  darwinports has a missing .dyld file, fink wants to reinstall X-windows...

  2. *Applescript with Preview should work just fine, Preview can read all these formats and can export in a bunch of useful formats.  Preview seems like a fairly key app for the Mac, but it is one of the few apps that can’t be scripted.  You can enable scripting, but still I can’t figure out how to get it to save.

  3. * Automator, too lame, I thought but the “Change type of images” action is nice.  Automator can be invoked from the command line like: automator -v -i image.pict pict2tiff.workflow

  4. *Graphics-converter for the Mac needs a licence

  5. *PythonMagick needs the boost library and that never went smoothly...

  6. *They Python Imaging class PIL is pretty nice but doesn’t read PICT format

  7. *sips.  Whoever heard of sips!  But check out the man page.  It’s a really nice command-line image manipulation tool, for example: sips --setProperty format jpeg image.pict -o image.jpg