Skip to content

Instantly share code, notes, and snippets.

@brock
Created January 23, 2015 00:49
Show Gist options
  • Save brock/ff3b45e33059500c6567 to your computer and use it in GitHub Desktop.
Save brock/ff3b45e33059500c6567 to your computer and use it in GitHub Desktop.
Export all photos in iPhoto. You are prompted for the directory they will be copied into. The original files are copied, and they get copied into individual folders for each date.
set destination to quoted form of POSIX path of (choose folder with prompt "Select the folder to create sub-folders and export photos")
tell application "iPhoto"
set tc to count photos
repeat with i from 1 to tc
try
tell photo i to my copyPhoto(date, image path, original path, title, destination)
end try
end repeat
end tell
on copyPhoto(d, p, origP, t, dest) -- the name of the file is the title of the photo in iPhoto, date format for folder name = 2014-09-25
tell d to set d to "" & its year & "-" & text -2 thru -1 of ("0" & ((its month) as integer)) & "-" & text -2 thru -1 of ("0" & its day)
try -- create folder if necessary, check to not overwrite any files in the subfolder, copy the file, rename with the title
do shell script "f=" & d & ";t=" & (quoted form of t) & ";tFile=" & (quoted form of origP) & "; e=${tFile##*.}; cd " & dest & ";mkdir -p \"$f\"; while [ -e \"$f/$t.$e\" ];do t=\"$t _\";done; cp -a \"$tFile\" \"$f/$t.$e\" && exit 0; cp -a " & (quoted form of p) & " \"$f/$t.$e\";echo 'test'"
end try
end copyPhoto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment