Monday, July 21, 2008

Script to update EXIF data in iPhoto '08


I shoot some photos with a digital Nikon D50, and some with a Leica M3 (35mm film). The pictures from the digital Nikon are encoded with plenty of detail in the EXIF tags, but the digitized images from the Leica and the 35mm film have only a few tags from the scanner.

I wanted a script that would update the desired EXIF tags direct in iPhoto. I looked around on the Internet at other scripts, and wrote a simple script to update a few EXIF tags on selected images in iPhoto.

I won't go into a full set of instructions here, but in summary these are simplified directions:

  1. Download and install the EXIFTool, which is a platform-independent Perl library.
  2. Enable GUI Scripting for AppleScript. In Finder, navigate to Applications -> AppleScript -> AppleScript Utility.
  3. Start Script Editor. In Finder, navigate to Application -> AppleScript -> Script Editor. Copy the code below into Script Editor, compile it to verify no errors, edit as desired for your camera make and model (or other EXIF tags), and save for future use.

-- original script written by Peter Samson
global iPhotoVersion, selectedPhotos
tell application "iPhoto" to set iPhotoVersion to (character 1 of (version as text)) as integer -- get iPhoto version
if iPhotoVersion < 7 then
error "This script requires iPhoto '08 (version 7.x) or later."
else
tell application "iPhoto"
set photoList to selection
set selectedPhotos to (count photoList)
if class of item 1 of photoList is album or selectedPhotos < 1 then
error "You must select one or more photos. This script will intentionally not process an album."
else
repeat with i from 1 to selectedPhotos
set this_photo to item i of photoList
tell this_photo
set image_file to the image path
end tell
set output to do shell script "exiftool -Make='Leica' -Model='M3' " & "'" & image_file & "'"
end repeat
end if
end tell
end if

The script looks ugly here but don't worry - it will be formatted and pretty when you compile it in Script Editor.

The script above will set two EXIF tags - set the Make to Leica and set the Model to M3. There are numerous EXIF tags available for use.

Now, using the script. Keep the script open in Script Editor. Open iPhoto '08 and select/highlight ONLY ONE(!) image as a test. The script is designed to alter the EXIF tag(s) for the image(s) that are selected in iPhoto. Go back to Script Editor and run the script - it should update the EXIF tag(s) for the selected image in iPhoto. Go back to iPhoto and look at the EXIF tag(s) for the selected image. Done!

1 comment:

Anonymous said...

Excellent script!
Presumably one could alter iPhoto to Aperture, limiting it to 2.1 or later?
Or have I missed something?