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

,

42 Responses to Rename and File Aperture Projects by Date


  1. Fatal error: Uncaught Error: Call to undefined function ereg() in /homepages/38/d204808225/htdocs/johneday/wp-content/themes/canvas/includes/theme-comments.php:63 Stack trace: #0 /homepages/38/d204808225/htdocs/johneday/wp-content/themes/canvas/includes/theme-comments.php(19): the_commenter_link() #1 /homepages/38/d204808225/htdocs/johneday/wp-includes/class-walker-comment.php(180): custom_comment(Object(WP_Comment), Array, 1) #2 /homepages/38/d204808225/htdocs/johneday/wp-includes/class-wp-walker.php(146): Walker_Comment->start_el('', Object(WP_Comment), 1, Array) #3 /homepages/38/d204808225/htdocs/johneday/wp-includes/class-walker-comment.php(140): Walker->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #4 /homepages/38/d204808225/htdocs/johneday/wp-includes/class-wp-walker.php(371): Walker_Comment->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #5 /homepages/38/d204808225/htdocs/johneday/wp-includes/comment-template.php(2091): Walker->paged_walk(Array, '5', 0, 0, Array) #6 /homepages/38/d20 in /homepages/38/d204808225/htdocs/johneday/wp-content/themes/canvas/includes/theme-comments.php on line 63