Created
May 10, 2010 23:54
-
-
Save talison/396711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Aperture" | |
activate | |
# Once the folder hierarchy is created, the photos must be | |
# moved into a project. This is the default name of the project. | |
set DEFAULT_PROJECT_NAME to "Photos" | |
set curSel to (get selection) | |
# Force the user to pick a selection. The parent of the selection is the container | |
# we'll grab all the images from to organize into the folder hierarchy. | |
if curSel is {} then | |
error "Please select a project to organize" | |
else | |
set currentProject to (get parent of item 1 of curSel) | |
# The year folders will be created at the root, which is | |
# defined as the parent of the current project. | |
set rootContainer to (get parent of currentProject) | |
tell currentProject | |
set max to (count every image version) | |
# Process each image until the queue is exhausted. | |
set current to 1 | |
repeat until current is greater than max | |
tell first image version | |
set targetFolder to {} | |
# Grab dates | |
set theDate to (get value of EXIF tag "ImageDate") | |
set theMonth to (get value of EXIF tag "CaptureMonthOfYear" as integer) | |
# Pad the string if it's less than 10 | |
if (length of (theMonth as string) is 1) then | |
set theMonth to "0" & theMonth | |
end if | |
# Set folder names | |
set yearFolderName to (get year of theDate as string) | |
set monthFolderName to ((theMonth as string) & " " & (get month of theDate)) | |
set yearFolder to {} | |
set monthFolder to {} | |
# Check to see if the year folder exists. Create it if not. | |
if not (exists folder yearFolderName in rootContainer) then | |
tell rootContainer | |
set yearFolder to make new folder with properties {name:yearFolderName} | |
end tell | |
else | |
set yearFolder to (get folder yearFolderName in rootContainer) | |
end if | |
# Check to see if the "month" folder exists within the current year folder. | |
# Create it if it needed. | |
if not (exists folder monthFolderName in yearFolder) then | |
tell yearFolder | |
set monthFolder to make new folder with properties {name:monthFolderName} | |
end tell | |
else | |
set monthFolder to (get folder monthFolderName in yearFolder) | |
end if | |
# Create a generic project called "Photos" in the month folder | |
if not (exists project "Photos" of monthFolder) then | |
tell monthFolder to make new project with properties {name:DEFAULT_PROJECT_NAME} | |
end if | |
move it to project DEFAULT_PROJECT_NAME of monthFolder | |
end tell | |
set current to current + 1 | |
end repeat | |
end tell | |
end if | |
end tell | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment