This is a script for renaming an image file by inserting the IPTC keywords from an image into the filename.

For example, if I add keywords to an image in Lightroom (or any other IPTC-based keyword program such as Aperture) they show up elsewhere, and survive copying to other file systems,

Lightroom keyword entry Mac OS X Preview Keywords

but they don't show up in the filename when exported:

Mac OS X Filename with no keywords

This script extracts the IPTC keywords from the file and inserts them into the filename so you get:

Mac OS X filename with IPTC keywords inserted

I use this when I'm exporting images from Adobe Lightroom as a post-processing script to include my keywords in the filename. (This is mostly for historic reasons -- my previous workflow just put keywords in the file name and I'd like to keep that for the time being.)

To use this script you need to put it in the "Export Actions" folder in your user Library folder under "Application Support/Adobe/Lightroom/Export Actions". However, Lightroom doesn't pass the names of the files to be processed on the command line, so to make this script work you need to create an AppleScript which just accepts the files from Lightroom and calls the script with them.

Installing:

This is a bit involved, but not hard.

1. The first thing you need to do is get ImageMagick and install it somewhere. This is the program the script uses to extract the IPTC keywords. You can either download the source, use the Terminal program and type ./configure and ./make inside the ImageMagick directory, or download the disk image and install it that way.

2. Once you've installed ImageMagick, you need to download the "iptc-rename.py" script. This is the script that processes the file to build up the new filename from the keywords. (You may need to make this file executable by executing "chmod +x SCRIPT" on the script in the Terminal, where SCRIPT is the full path to the iptc-rename.py including the script name.)

The "iptc-rename.py" script needs to know where ImageMagick is located. To do this change the line that say:

imageMagick = "/Applications/PATH_TO_YOUR_INSTALL/ImageMagick-6.3.2"

to have the correct path to wherever you installed ImageMagick.

3. Next you need to create the AppleScript droplet that Lightroom will use to pass the files to the "iptc-rename.py" script. To do this open the ScriptEditor program and paste in the following script:

on open theObjects
    repeat with theObject in theObjects
       do shell script "'/Users/USERNAME/Library/Application Support/Adobe/Lightroom/Export Actions/iptc-rename.py' " & (POSIX path of theObject as string)
    end repeat
end open 

You will need to change the "/Users/USERNAME/Library/Application Support/Adobe/Lightroom/Export Actions/iptc-rename.py" part to point to wherever you put the "iptc-rename.py" script.

Now save the AppleScript as an Application in your Lightroom "Export Actions" folder as "iptc-rename-droplet".

Exporting files with IPTC Keywords in the Filename:

When exporting from Lightroom simply choose the AppleScript as a post-processing script when you export your files:

Lightroom export filenames with IPTC keywords

When you export your files, Lightroom will first export them all, then run them all through the script, which will append the keywords to the filename. If you want to have the keywords separated by something other than a space simply change the keywordSeparator=" " line to whatever you'd like.

Note: I use this script on a Mac under OS X. For other OSes the iptc-rename.py script should work fine as long as ImageMagick is installed, but it may not integrate with Lightroom.

This script is provided "as is" with no guarantees. Good luck with it, but don't blame me if anything goes wrong!

Copyright © David Black-Schaffer 11 September 2007