Aperture: Applescript to access Aperture library generates an error under Leopard

Issue or symptom

An AppleScript used to select a project in Aperture may generate the error message "Aperture got an error: Can't get project 'yourprojectname'" when run on Mac OS X 10.5 Leopard. The same script runs without an error message on Mac OS X 10.4 Tiger.

Solution

This may happen if you do not specify the library to be used in your script. This has always been the best practice, but it was not mandatory under OS X 10.4.x. For example, this script fragment will generate the error message:

tell application "Aperture"
      activate

      set x to name of every project
      choose from list x with prompt "Select a project"
      set ap_proj to item 1 of result
      set ap_proj to project ap_proj

end tell

The solution is to add the following line to the script, on the line below tell application "Aperture":

tell library 1

You will also need to add an additional end tell statement on the line before the existing end tell. So the resulting script fragment will look like this:

tell application "Aperture"
      tell library 1
        activate

        set x to name of every project
        choose from list x with prompt "Select a project"
        set ap_proj to item 1 of result
        set ap_proj to project ap_proj
     end tell
end tell

Published Date: Feb 20, 2012