AppleScript exporting photos from Aperture

The following AppleScript will:

  • Prompt for a destination folder
  • Ask for an album name, which will be a folder in destination folder
  • Get currently selected photo(s) from Aperture
  • Store the image files using the Image ID of Aperture
  • Store some META information in a text file, with similar name as image file

The export format is PNG 1024x1024. I needed only that, so I hardcoded it.

Note dependencies: You need the renameFile, joinList and splitString functions found in earlier blog entries.

property defExportSetting : "PNG - Fit within 1024 x 1024"

on apertureExport(fldAlbum)
 tell application "Aperture"
  set imageSel to (get selection)
 end tell

 set out to {}
 repeat with img in imageSel
  tell application "Aperture"
   set kwList to (get id of every keyword of img)
   set imgDate to value of EXIF tag "ImageDate" of img
  end tell
  set imgId to id of img

  set imgName to name of img
  set imgTags to my joinList(kwList, ",")

  copy "Name: " & imgName to end of out
  copy "Tags: " & imgTags to end of out
  copy "ApertureId: " & imgId to end of out

  set dstFileMeta to (fldAlbum & imgId & ".meta") as string
 end repeat

 tell application "Aperture"
  set dstFile to (export imageSel using export setting defExportSetting to fldAlbum)
 end tell
 set dstFile to my renameFile(dstFile, imgId)
 copy "File: " & (POSIX path of dstFile) to end of out
 tell application "Finder"
 end tell

 set fp to open for access file dstFileMeta with write permission
 write (joinList of out given delimiter:return) to fp
 close access fp

end apertureExport

on run
 set dstFolder to (choose folder with prompt "Choose an destination") as text
 set dlgAlbum to display dialog "Album name" buttons {"OK", "Cancel"} default answer "Picture pool"

 set dstAlbum to (text returned of dlgAlbum) as text

 tell application "Finder"
  if not (exists alias (dstFolder & dstAlbum)) then
   make new folder at alias (dstFolder) with properties {name:dstAlbum}
  end if
 end tell
 set fldAlbum to (dstFolder & dstAlbum) as alias

 apertureExport(fldAlbum)
end run

This script is safe, but I don’t take any responsibility when it screws up you Aperture library. It shouldn’t really, I coded it on my main library: hardcore!