Rename and File Aperture Projects by Date

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

,

40 Responses to Rename and File Aperture Projects by Date

  1. H August 22, 2012 at 9:32 am #

    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

    • H August 22, 2012 at 10:34 am #

      worked it out… only fails when using with photostream project.

      thanks

      h

    • johneday August 25, 2012 at 1:10 am #

      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

      • Oliver Henlich February 7, 2013 at 7:04 pm #

        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

        • johneday February 8, 2013 at 6:30 pm #

          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.

  2. Paul September 4, 2012 at 12:17 am #

    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”

    • johneday September 4, 2012 at 12:27 am #

      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

  3. Max September 18, 2012 at 1:18 am #

    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.

    • johneday September 18, 2012 at 2:26 am #

      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

  4. Max September 18, 2012 at 2:47 am #

    awesome, thanks for the quick reply and the very handy script!

  5. kevin October 13, 2012 at 5:32 pm #

    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

    • kevin October 15, 2012 at 1:03 am #

      I figured it out.

      just needed to set folderYear as a string and use that instead of projectYear.

      Thanks again for an awesome script!

  6. johneday October 15, 2012 at 9:16 pm #

    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

  7. g2 January 31, 2013 at 1:11 pm #

    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

    • johneday February 1, 2013 at 3:25 am #

      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

      • g2 February 1, 2013 at 2:10 pm #

        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…

        • johneday March 1, 2013 at 3:38 am #

          I posted an update today. Let me know if it solves your issue.

  8. Daryl February 28, 2013 at 10:17 pm #

    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

    • johneday March 1, 2013 at 3:38 am #

      Hi Daryl. I have updated the script to include some additional error checking. Tell me if it does the trick.

  9. Jeff March 25, 2013 at 2:13 am #

    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

  10. Pete April 1, 2013 at 4:04 am #

    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?

    • johneday April 1, 2013 at 5:23 pm #

      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

      • Pete April 5, 2013 at 2:54 am #

        I’ll give it a try, thanks for the help. I’ll post my script if I get it working.

  11. Amanda May 17, 2013 at 12:50 pm #

    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!

    • johneday May 17, 2013 at 1:28 pm #

      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.

      • Amanda May 17, 2013 at 4:27 pm #

        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}

        • johneday May 23, 2013 at 10:25 am #

          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.

      • Jacob August 1, 2013 at 1:56 am #

        I am also getting “error number -10004,” you said “Select one of your images and run the following script.” How do I know which image to select (i.e. which one is causing the error)? Or can I select any image? The last few lines of output are:

        move every image version of folder id “2DO+OjCLTo6CEh7kmYfhtg” whose value of EXIF tag “CaptureYear” = 2068 and value of EXIF tag “CaptureMonthOfYear” = 1 and value of EXIF tag “CaptureDayOfMonth” = 19 to project “2068-01-19″ of folder “Imported by Date” of library 1
        count every image version of folder id “2DO+OjCLTo6CEh7kmYfhtg”
        –> 501
        beep library 1
        –> error number -10004

        • johneday August 2, 2013 at 11:54 pm #

          Hi Jacob. The script locates the project which contains the photos by finding the parent of one selected image. The error handler was designed to file photos that did not have problems with their exif data and to skip those which did. Feel free to get in touch the week of the 12th via Skype and I will try to sort it out for you.

  12. Niko July 9, 2013 at 5:11 pm #

    Hi Johneday.

    First of all thanks a lot for your script but I do get a slight problem.
    I set the section below as following:

    set yourFolder to “Imported by Date” — Name your folder here
    set appendParent to true — 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 {}

    and I don’t get the name ogf the file anymore when I run the script only the date of the Exif.

    I’m under 10.8.4.

    Any idea where I ‘m wrong
    thanks

    • johneday July 11, 2013 at 2:12 pm #

      Hi Niko. The appendParent property is meant to add the name of the original project to the end of the newly created projects. Beach -> 2012-04-15 Beach. Are you saying that the names of the projects are no longer appended to the new projects’ names?

  13. Patrick July 13, 2013 at 11:49 pm #

    Any thoughts on how to handle hundreds of projects named in Aperture’s “Jan-01-2013″ format, but where I’ve added names after the dates for very many of them?

    If I use the appendParent flag, I end up with two dates in the project name:

    2013-01-01 Jan-01-2013 MyNameOfProject

    What I’d really like to end up with is just:

    2013-01-01 MyNameOfProject

    The date formatting at import has driven me nuts since I first started using Aperture.

    - Patrick

    • johneday July 16, 2013 at 5:10 pm #

      Hi Patrick,

      If you can simply remove the text before the first space, the code below should help you with the projects named in Aperture’s format. Remember to use the original script once you have renamed these files.

      Change this line
      if appendParent then set isoImageDate to isoImageDate & space & parentName
      to
      if appendParent then set isoImageDate to isoImageDate & space & my removeFirstWord(parentName)

      Add this handler to the end of the script.
      on removeFirstWord(theText)
      set {TID, text item delimiters} to {text item delimiters, space}
      set theText to text items 2 thru -1 of theText
      set text item delimiters to TID
      return theText
      end removeFirstWord

  14. Dan Blanchard September 29, 2013 at 10:35 am #

    Hi John,

    First of all, thanks for the amazingly useful script.

    I’ve had a problem for a while where videos transferred to my Mac from my iPhone via Dropbox don’t maintain the proper date/time information. However, the app I use to do the syncing does include the proper date and time in the filename. They’re all named in the format “YYYY-MM-DD at HH.mm.ss”.

    What I’d like to do is modify your script so that if the filename is in that format, it should first set the timestamp of the file (since video files don’t have EXIF data as far as I understand) and then continue on as normal. Where do you think would be a good spot to change that? And does your script handle timestamps for movies in the first place?

    Thanks,
    Dan

    • Dan Blanchard September 29, 2013 at 12:46 pm #

      I actually ended up just writing a little Python script to fix all those timestamp issues and then ran “Update from original” on all of the video files, which seems to have fixed the timestamps. Now I’m getting an error when I run your script though:

      Aperture got an error: Can’t get EXIF tag “ImageDate” of every image version of project id “z7ioXuMjQ0ibZAdSjoIZdg”.

      I guess this means it can’t handle videos?

  15. Michael Young October 24, 2013 at 10:33 pm #

    I’m getting a -1728 error on almost all of my photos. The script generates this error related to “and value of EXIF tag “CaptureDayOfMonth” is day of aDate as integer” in the move command. I have 1,000s of images in my albums for which I’ve sampled a handful of listed files that failed. All of the listed files have valid EXIF data.

    To get around this problem, I removed the “and value of EXIF tag “CaptureDayOfMonth” is day of aDate as integer” from the move command. Since we are only moving images into folders based on the year and month, I figured there is no point checking the day of the month as well.

    The script works fine so far with these changes.

    • Michael Young October 24, 2013 at 10:50 pm #

      I was wrong. It works if I select a single project, but if I select a folder with multiple projects, the pictures end up in “missing”. They aren’t in the old project or the new project and they aren’t the trash. I’ll have to reimport them.

  16. Matt December 18, 2013 at 1:00 am #

    Thanks so much. You’re a lifesaver.

  17. Francis Mariani May 19, 2014 at 1:25 am #

    This is a great script! I’ve wanted to do this for a long time and only just stumbled on this post. Thanks very much, and thanks for making it configurable.

Leave a Reply