-- Aperture iPhoto Sync script (by Devarshi Shah - publicdev [at] mac [dot] com) -- This script will let you select one (or more) projects/albums from the Aperture library -- and will transfer the pictures from them into iPhoto. A few things to note: -- a. The script is currently written to process max 2 levels of nesting. -- b. For nested albums/projects, the corresponding album created in iPhoto will -- always be named after the innermost nested album/project. This is an iPhoto -- limitation - the inability to create nested albums using Applescript. -- c. If the album with the same name exists in iPhoto, it will get appended to. -- d. Currently, this script should not sync up modified versions - only masters -- get synched up. -- e. If you have "Copy files to iPhoto Library folder when adding -- to Library" preference in iPhoto unchecked, this script will create links - thereby -- saving you some (actually lots !) diskspace ! -- f. This script currently assumes that the Aperture library is located at -- ~/Pictures/Aperture Library.aplibrary/. If your library isnt, replace the -- apertureLibraryFileName with the correct prefix. NOTE : As you can see, I -- tried to determine this automatically from the plist, but apparently, when -- it gets used later down when executing shell script, the terminal doesnt like -- the spaces in the file name. If you know how to solve that problem, let me know and -- I'll fix it ! -- g. Only tested with Aperture v1.1.2 & iPhoto v6.0.4 -- h. This is very much alpha version - though I've tested it and its worked great -- for me, use at your own risk. Having said that, I'd be more than happy to fix -- the problems that you may encounter, so feel free to let me know. set origTextItemDelimiters to AppleScript's text item delimiters tell application "System Events" set apertureLibraryPath to value of property list item "LibraryPath" of ¬ property list file ((path to preferences as Unicode text) & "com.apple.Aperture.plist") set apertureLibraryFileName to "~/Pictures/\"Aperture Library.aplibrary\"/Aperture.aplib/Library.apdb" --set apertureLibraryFileName to (apertureLibraryPath & "/Aperture.aplib/Library.apdb") end tell tell application "Aperture" activate -- select a project from a list of all projects, and then select all images in that project set allProjects to name of every «class rkfl» set selectedProjectName to (choose from list of allProjects) set subProjectList to {} if exists every «class rkpj» in «class rkfl» (selectedProjectName as string) then set subProjectList to subProjectList & (name of every «class rkpj» in «class rkfl» (selectedProjectName as string)) end if if exists every «class rkal» in «class rkfl» (selectedProjectName as string) then set subProjectList to subProjectList & (name of every «class rkal» in «class rkfl» (selectedProjectName as string)) end if end tell -- If the folder selected contains any child projects or -- albums, ask the user to select them. Else continue assuming -- that the folder is what needs to be processed. It would be wise to remember that -- a "folder" could be a project or an actual folder ! if subProjectList is not {} then set selectedSubProject to (choose from list of subProjectList with title "Select album(s)/project(s)..." with multiple selections allowed) set subProjectList to selectedSubProject set nestedSelection to true else set subProjectList to {selectedProjectName} set nestedSelection to false end if set numSubProjectsImported to 0 if subProjectList is not {} then repeat with selectedSubProject in subProjectList set imagesInSelectedProject to {} tell application "Aperture" if nestedSelection then if exists («class rkpj» (selectedSubProject as string) in «class rkfl» (selectedProjectName as string)) then set imagesInSelectedProject to every «class rkdp» of («class rkpj» (selectedSubProject as string) of «class rkfl» (selectedProjectName as string)) else set imagesInSelectedProject to every «class rkdp» of («class rkal» (selectedSubProject as string) of «class rkfl» (selectedProjectName as string)) end if else if exists «class rkpj» (selectedSubProject as string) then set imagesInSelectedProject to every «class rkdp» of «class rkpj» (selectedSubProject as string) else if exists «class rkal» (selectedSubProject as string) then set imagesInSelectedProject to every «class rkdp» of «class rkal» (selectedSubProject as string) end if end if end tell if imagesInSelectedProject is not {} then -- now get the unique IDs of each image and make it into a list that can be used for the -- SQL query that we shall do next set imageIDList to "' '" repeat with this_image in imagesInSelectedProject set imageIDList to imageIDList & ",'" & (id of this_image) & "'" end repeat -- perform the SQL query and get the results set sqlQuery to "/usr/bin/sqlite3 " & apertureLibraryFileName & " \"select zrkfolder.ZLIBRARYRELATIVEPATH, zrkmaster.ZIMPORTGROUP, zrkmaster.zname, zrkfile.zname from zrkfolder, zrkversion, zrkmaster,zrkfile where zrkfile.z_pk = zrkmaster.zoriginalfile AND zrkmaster.z_pk = zrkversion.zmaster AND zrkfolder.zuuid = zrkversion.zprojectuuid AND zrkversion.zuuid IN (" & imageIDList & ");\"" --log (sqlQuery) set imageParamsString to (do shell script sqlQuery) -- parse the results : now each item of the list shall contain a record set AppleScript's text item delimiters to return set imageParamsList to text items of imageParamsString set AppleScript's text item delimiters to "|" -- now parse all records and generate a list of image paths to be imported into iPhoto set imageList to {} repeat with this_image_param in imageParamsList if this_image_param is not "" then set imageParams to text items of this_image_param set imagePath to apertureLibraryPath & "/" & (item 1 of imageParams) & "/" & (item 2 of imageParams) & "/" & (item 3 of imageParams) & "/" & (item 4 of imageParams) set imageList to imageList & imagePath end if end repeat -- finally ask iPhoto to create a new album if needed and -- import the photos tell application "iPhoto" activate if not (exists (album (selectedSubProject as string))) then new album name (selectedSubProject as string) end if set the_album to album (selectedSubProject as string) import from imageList to the_album without force copy end tell set numSubProjectsImported to numSubProjectsImported + 1 end if end repeat end if display dialog "Aperture iPhoto Sync Results : " & (numSubProjectsImported as string) & " Project(s)/Album(s) Queued for import to iPhoto." buttons {"Ok"} set AppleScript's text item delimiters to origTextItemDelimiters