Although every Aperture 3 user organizes their projects differently, I am sure most of you have some unfiled, unnamed, and otherwise unorganized projects floating around your Library. To prevent having an unmanageable sidebar with endless scrolling, I file these projects in a folder until I find a home for them.
Select a project, folder, or album from the sidebar and run the script. Projects named YYYY-MM-DD are created in the “Imported by Date” folder and all items of the selected project are filed according to their EXIF tag ImageDate. I prefer using the ISO 8601 date format 2011-08-27 rather than the default Aug 27, 2011, especially when working with long lists. Download
set yourFolder to "Imported by Date" -- Name your folder here
set appendParent to false -- If true, the selected parent's name will be appended to the new project name
set makeSubfolders to false -- If true, new projects will be created in year/month/ folders.
property delimiter : "-"
set exifProblems to {}
tell application "Aperture"
activate
-- Wait until Aperture is finished processing other tasks
repeat
set taskCount to count of tasks
if taskCount is 1 then
display alert "Aperture is processing another task" message "Please wait for the task to complete and try again" buttons {"Try again", "Cancel"} default button {"Try again"} cancel button {"Cancel"}
else if taskCount > 1 then
display alert "Aperture is processing " & taskCount & " tasks" message "Please wait for the tasks to complete and try again" buttons {"Try again", "Cancel"} default button {"Try again"} cancel button {"Cancel"}
else
exit repeat
end if
end repeat
-- Verify that at least one item is selected
if selection is {} then display alert "The selection {} is empty" message "Please select ONE Project, Folder or Album from the Library tab in the sidebar and try again." buttons {"OK"} cancel button {"OK"}
-- Get the selected Parent ID
tell item 1 of (selection as list) to set theParent to parent
set {parentClass, parentName} to {class, name} of theParent
if parentClass is album then display dialog "Albums may contain images from multiple projects. Are you sure you want to move these images from their projects?"
-- Get date of every image in the selected Parent
tell theParent to set dateList to every image version's (value of EXIF tag "ImageDate")
tell library 1
-- Create your folder if it does not exist
if not (exists folder yourFolder) then make new folder with properties {name:yourFolder}
-- Assign name of every project in your folder to a list for the Create project command below
-- (exists project isoImageDate) command is too slow to be included in the loop
if not makeSubfolders then tell folder yourFolder to set parentList to name of every project
set dateTest to {}
repeat with aDate in my dateList
-- Test each date to avoid processing duplicates
set shortDate to short date string of aDate
if dateTest does not contain shortDate then
set end of dateTest to shortDate
-- Convert the image date to YYYY-MM-DD format
set projectYear to year of aDate as string
set projectMonth to (month of aDate as integer) as string
if length of projectMonth is 1 then set projectMonth to "0" & projectMonth
set projectDay to (day of aDate as integer) as string
if length of projectDay is 1 then set projectDay to "0" & projectDay
set isoImageDate to projectYear & delimiter & projectMonth & delimiter & projectDay as string
if appendParent then set isoImageDate to isoImageDate & space & parentName
tell folder yourFolder
if makeSubfolders then
--Create year and month folders if year folder does not exist
if not (exists folder projectYear) then make new folder with properties {name:projectYear}
tell folder projectYear
if not (exists folder projectMonth) then make new folder with properties {name:projectMonth}
end tell
--Create project if it does not exist
if ((name of every project of folder projectMonth of folder projectYear) does not contain isoImageDate) then tell folder projectMonth of folder projectYear to make new project with properties {name:isoImageDate}
try
-- Move the images into the project
move (every image version of theParent whose value of EXIF tag "CaptureYear" is year of aDate and value of EXIF tag "CaptureMonthOfYear" is month of aDate as integer and value of EXIF tag "CaptureDayOfMonth" is day of aDate) to project isoImageDate of folder projectMonth of folder projectYear
on error
set targetProject to project isoImageDate of folder projectMonth of folder projectYear
tell me to set exifProblems to exifProblems & exifCheck(theParent, aDate, targetProject)
end try
else -- If not makeSubfolders
--Create project if it does not exist
if parentList does not contain isoImageDate then make new project with properties {name:isoImageDate}
try
-- Move the images into the project
move (every image version of theParent whose value of EXIF tag "CaptureYear" is year of aDate and value of EXIF tag "CaptureMonthOfYear" is month of aDate as integer and value of EXIF tag "CaptureDayOfMonth" is day of aDate) to project isoImageDate
on error
set targetProject to project isoImageDate
tell me to set exifProblems to exifProblems & exifCheck(theParent, aDate, targetProject)
end try
end if
end tell
end if
end repeat
-- Move the initial container to the Trash if no images remain or if it is an album
if parentClass is album then
delete theParent
else if (count of image versions of theParent) is 0 then
delete theParent
end if
beep
end tell
end tell
if exifProblems ≠ {} then
set exifProblems to text 1 thru -3 of (exifProblems as text)
tell me
activate
display alert "The script had problems processing EXIF info: " message (exifProblems as text) buttons {"OK"} default button 1 cancel button 1
end tell
end if
on exifCheck(theParent, aDate, destination)
tell application "Aperture"
script o
property parentImages : every image version of theParent
property badExif : {}
end script
repeat with anImage in o's parentImages
try
if value of EXIF tag "CaptureYear" of anImage is year of aDate and value of EXIF tag "CaptureMonthOfYear" of anImage is month of aDate as integer and value of EXIF tag "CaptureDayOfMonth" of anImage is day of aDate then move anImage to destination
on error
set end of o's badExif to (anImage's name) & "," & space
end try
end repeat
return o's badExif
end tell
end exifCheck






Hi
This is a fantastic script and I’ve been using it for a few months, however since the last update of Aperture it seems to have stopped recognising when a project is selected in Aperture 3.3.2. Any tips for getting it working… I can’t live with out it!
Thanks
H
worked it out… only fails when using with photostream project.
thanks
h
Hi H,
Thanks for pointing out the issue with photostream projects. I am still running 3.2.4 and will consider updating the script after I have installed the latest version of Aperture.
John
Hi John,
Just tried this on a photo stream folder too in the hope of sorting out all those photos from our phones but it looks like the selection variable still does not contain anything when selecting a photo stream project. I can confirm it does work with a non-photo stream project. Any ideas, any pointers?
Cheers
Oliver
Hi Oliver. I plan on upgrading to Mountain Lion within the next few weeks. As soon as I do, I will check the functionality of photo stream projects.
Thanks for the script! How would I just append the date to the front of the title that already exists for the project? For example, if the project was titled “birthday party” the script would change the title to “2012-01-23 birthday party”
Hi Paul,
I have updated the script to include an “appendParent” variable which, if set to true, will append the selected parent’s name to the new project name.
John
Is it just me?!?!?!? It only works one at a time. I try highlighting multiple projects and then running the script, but it will only run one of them.
Hi Max,
You must select ONE Project, Folder or Album from the Library tab in the sidebar. If you want to process multiple projects at once, simply combine them into a single project before you run the script.
John
awesome, thanks for the quick reply and the very handy script!
Hi Johneday,
I’m new to Aperture and I’m trying to consolidate all my images across multiple applications / filesystems. I came across this script from the ApertureExpert.com website and it was exactly what I was looking for.
How could I have the script put the projects into a nested hierarchy of / /
I tried to modify the script but I keep getting an error when it tries to create the projects in the nested folders
here is what I’ve tried so far :
—-
if appendParent then set isoImageDate to isoImageDate & space & parentName
set projectMonthName to month of aDate as string
+++
set projectMonthName to month of aDate as string
set folderMonth to projectMonth & space & delimiter & space & projectMonthName
tell folder yourFolder
— create a folder with the year as the name in yourFolder
if not (exists folder projectYear) then make new folder with properties {name:projectYear}
— create a folder in the year folder with the format of “projectMonth – projectMonthName
tell folder projectYear
if not (exists folder folderMonth) then make new folder with properties {name:folderMonth}
end tell
+++
–Create project if it does not exist
if parentList does not contain isoImageDate then make new project with properties {name:isoImageDate}
—-
This is the error I’m getting :
Result:
error “Aperture got an error: Can’t get folder 2009 of folder \”Imported by Date\” of library 1. Invalid index.” number -1719 from folder 2009 of folder “Imported by Date” of library 1
Also when I run it again with out removing the Import directory it creates another directory name of the year. In this case “2009 (1)”. My guess is that it is loosing the reference to the root folder object “Imported by Date”
– Kevin
I figured it out.
just needed to set folderYear as a string and use that instead of projectYear.
Thanks again for an awesome script!
Hi Kevin,
I’m glad you figured it out. I have found that by including an (exists project) or (exists folder) in the loop, the script becomes noticeably slower. I have posted an update which builds the year and month lists at the beginning of the script, hopefully shaving off a few seconds.
John
Thanks for the script! Unfortunately for me, it ran fine once, then upon subsequent tries, no longer appears to work. I am running the latest version of Aperture. I even restarted Aperture between tries but no luck. Is there something I am doing wrong?
Thanks!
g2
Although I am unsure what was causing your issue, I updated the script today to improve its readability. Tell me if you have more luck with this version.
John
Thanks John… it still runs but has no effect… I checked that it runs by not selecting an object and seeing the warning message posted. But nothing happens when I select a project and run it…
I posted an update today. Let me know if it solves your issue.
Hi John,
The script worked for some of my projects, then I decided to merge everything into one big project to run it all in one go and now I keep getting the message “Aperture got an error: Can’t get EXIF tag “CaptureDayOfMonth”".
I’ve tried running a filter in Aperture to identify which photos haven’t got EXIF date tags on them but found nothing.
In the script results I find this “error “Aperture got an error: Can’t get EXIF tag \”CaptureDayOfMonth\”.” number -1728 from EXIF tag “CaptureDayOfMonth”
Would you know how I could either get it to work or to identify the culprit?
Thanks,
Daryl
Hi Daryl. I have updated the script to include some additional error checking. Tell me if it does the trick.
John,
Thanks for publishing this very useful script. It works great to make up for a few areas that Aperture is lacking, especially a more useful, sortable date system – “2013-03-17″. As well, this helped me get around an error of Aperture not always splitting days up correctly.
Greatly appreciated!
Jeff
I am trying to write something similar to work on consolidating older projects (mostly brought in from my original iPhoto library). What I want to do is merge several projects, but first making an album out of the entire contents of each project, so that when the projects are combined, all the original groups are now albums inside the single combined project.
I am struggling just with the basics of applescript. When I mod your code for the parent (to find the project) it keeps finding the whole library 1. Perhaps acting on multiple projects isn’t possible?
Hi Pete. The best way I have found to get multiple projects is by selecting all of the images within them and running the script below.
tell application "Aperture"set selectedProjects to {}
set mySelection to selection
set dupeProjectTest to {}
repeat with imageVersion in mySelection
set imageVersion to (contents of imageVersion)
if imageVersion's id is not in dupeProjectTest then
set theProject to (first project whose image versions contains imageVersion)
set end of selectedProjects to theProject's id
set dupeProjectTest to dupeProjectTest & theProject's image versions's id
end if
end repeat
end tell
return selectedProjects
I’ll give it a try, thanks for the help. I’ll post my script if I get it working.
I have used this script successfully for +60k photos as I am rebuilding a library. However there were some photos left behind and i am not sure why. I have consolidated all of the leftovers into a folder and have tried to run the script on them and I get error 10004. There are only 700 left to run. Thanks!
Hi Amanda. I wrote an error handler in the script to skip images whose exif data produce an error. Select one of your images and run the following script:
tell application "Aperture"set anImage to first item of (get selection)
set CaptureYear to value of EXIF tag "CaptureYear" of anImage
set CaptureMonthOfYear to value of EXIF tag "CaptureMonthOfYear" of anImage
set CaptureDayOfMonth to value of EXIF tag "CaptureDayOfMonth" of anImage
end tell
return CaptureYear & CaptureMonthOfYear & CaptureDayOfMonth
It should produce an error as well. Feel free to get in touch via Skype and send me several of the failed images. You can also re-importing the images and running the script again.
So i ran that script on a few photos and it did not issue an error and the format doesn’t look to be an issue.
This is an example of what returns from a photo that did move with the original script:
{2002.0, 1.0, 23.0}
This is an example of what returns from a photo that did gave me the original error message:
{2008.0, 10.0, 25.0}
Hi Amanda. If you would like to get in touch via Skype and send me some of the problem photos, I would be happy to take a look at them.