Skip to content

Instantly share code, notes, and snippets.

@lowply
Created April 21, 2016 09:28
Show Gist options
  • Save lowply/1079759e66fd21fd42c9c4da3d1a39c7 to your computer and use it in GitHub Desktop.
Save lowply/1079759e66fd21fd42c9c4da3d1a39c7 to your computer and use it in GitHub Desktop.
Dump photos of each album in Aperture and import them into Photos.app
global yr
set yr to "2012"
global basePath
set basePath to "Storage:Pictures:ApertureExport:" & yr & ":"
tell application "System Events"
set exportFolder to basePath
end tell
on exportAlbum(targetAlbum)
set targetAlbumName to name of targetAlbum
tell application "Finder"
make new folder at basePath with properties {name:targetAlbumName}
end tell
tell application "Aperture"
set imageList to (every image version in targetAlbum)
export imageList to basePath & targetAlbumName & ":" metadata embedded
end tell
do shell script "find /Volumes/Storage/Pictures/ApertureExport -name .DS_Store | xargs rm -f"
do shell script "find /Volumes/Storage/Pictures/ApertureExport -type f -print0 | xargs -0 chflags nouchg"
end exportAlbum
on getAlbumList()
tell application "Aperture"
set myProject to get project yr
set myAlbums to every album of myProject
end tell
return myAlbums
end getAlbumList
on importToAlbum(a)
tell application "Photos"
set parentFolder to get folder yr
make new album named a at parentFolder
set targetAlbum to get album a
set extensionList to {"JPG", "jpg", "AVI", "avi", "MOV", "mov"}
set imageList to {}
set importFolder to basePath & a as alias
tell application "Finder" to set theFiles to every file of importFolder whose name extension is in extensionList
repeat with i from 1 to number of items in theFiles
set this_item to item i of theFiles as alias
set the end of imageList to this_item
end repeat
import imageList into targetAlbum skip check duplicates no
end tell
end importToAlbum
repeat with currentAlbum in getAlbumList()
set currentAlbumName to name of currentAlbum
display dialog "Export & Import " & currentAlbumName & " ?" buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"
set answer to button returned of result
if answer = "OK" then
exportAlbum(currentAlbum)
importToAlbum(currentAlbumName)
else
return
end if
end repeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment