Hi,
Almost certainly a colossal noob question, but I’ve found two different Applescripts to perform a task - changing the naming format of a project from the default e.g. Jan 01, 2010 to YYYY-MM-DD. One was from here (I think), the other was on Github.
What I want it to do is change the name in place, for the project(s) selected. Not make copies, or move projects to subfolders etc.
I don’t know enough about Applescript to get a feel for what they’ll do just by reading the code - if anyone else would be able to look at them and let me know, I’d appreciate it.
Thanks:
Option One:
set yourFolder to "Imported by Date" -- Name your folder here
set {dateList, dateTest, parentList} to {{}, {}, {}}
property delimiter : "-"
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 to class 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
tell folder yourFolder to set parentList to name of every project
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
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
tell folder yourFolder
--Create project if it does not exist
if parentList does not contain isoImageDate then make new project with properties {name:isoImageDate}
-- 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
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
Option Two:
tell application "Aperture"
set mons to {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
set digits to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
set ps to projects
repeat with p in ps
set nameStr to name of p
set yearNum to 0
set monthNum to 0
set dayNum to 0
set monthStr to (characters 1 thru 3) of nameStr as rich text
repeat with i from 1 to the count of mons
if item i of mons is monthStr then
set monthNum to i
end if
end repeat
try
set yearStr to (characters 9 thru 12) of nameStr as rich text
set yearNum to yearStr as number
set dayStr to (characters 5 thru 6) of nameStr as rich text
set dayNum to dayStr as number
end try
if monthNum > 0 and monthNum < 13 and dayNum > 0 and dayNum < 32 and yearNum > 1900 then
set len to (count of nameStr)
if len > 12 then
set r to (characters 13 thru len) of nameStr as rich text
else
set r to ""
end if
set newName to yearStr & "-"
if monthNum < 10 then
set newName to newName & "0"
end if
set newName to newName & (monthNum as rich text) & "-" & dayStr & r
log nameStr & " => " & newName
set name of p to newName
end if
end repeat
end tell