You are here

16 posts / 0 new
Last post
Automated Project Naming #1
Tim Doyle's picture
by Tim Doyle
August 31, 2011 - 4:05am

I have adopted the project naming format that Joseph uses & suggests - that of “2011-08-30 | Event Name”. When I migrated from iPhoto, I had hundreds of projects that all needed to be renamed to this format. Instead of doing this manually, I wrote a script which loops through each project in a specified folder, and for each project, loops through each included photo looking for the one with the earliest date. It then renames the project to the above format using this date, and moves to the next project. Although not as fast as I would like, it does the job and renamed all of my projects. I now use it each time I import photos from my cameras, iPhone, or iPad. I simply download photos, separated by date, into a specific folder (named “Events”), and then run the script. Automagically, all projects are renamed (leaving the existing name as the “Event Name” portion of the name, and I then move them into the appropriate year folders.

If anyone else is interested, I can post this script.

Tim Doyle's picture
by Tim Doyle
February 24, 2012 - 2:00am

I’ll have to make some edits to get it to parse through subfolders.

I think it should already work for not having the Events folder at the top level. I once had an issue where I had trashed the Events folder & created a new one, and when I ran the script, it was finding & processing the one in the trash. Since it sound it there, it might just work if you rename any folder “Events”. Of course, you can also just change the rootFolder parameter in the script & have it process whichever folder you’d like without having to rename it in Aperture.

PhotoJoseph's picture
by PhotoJoseph
February 24, 2012 - 3:00am

Tim,

Thanks for the reply. I do think that parsing subfolders would be a great addition.

I’m impressed more and more every day with what can be achieved in AppleScript!

@PhotoJoseph
— Have you signed up for the mailing list?

Andreas Frandsen's picture
by Andreas Frandsen
February 11, 2012 - 4:12am

a bit old message, but still - it would be great.

Maybe I don’t need it, but I wan’t my projects labelled with Year/Month/date and can’t find where to change this kind of silly format!

Thanks
Andreas

PhotoJoseph's picture
by PhotoJoseph
February 11, 2012 - 7:38am

Andreas,

If Tim doesn’t reply (he may not be subscribed to this message) I believe you can contact him by clicking his name in the post above.

As far as renaming projects, there’s no automatic naming of projects in Aperture. What I do is I use the app TextExpander which I gotta say is about the best $35 investment in software. I have a shortcut so that when I type “ymd” it expands to “yyyy-mm-dd | ” (obviously the yyyy and so-on are the current date).

@PhotoJoseph
— Have you signed up for the mailing list?

Tim Doyle's picture
by Tim Doyle
February 16, 2012 - 11:29pm

Andreas:

Here is the script:

(*
Rename Aperture Projects

This script loops through each project located within the “Events” folder in Aperture. For each project
found, all photos within are examined, and the oldest photo’s date is used to rename the project to the
format “YYYY-MM-DD | Previous_Project_Name”. This script can be used each time you import, and then
the projects can be moved to other folders. Make sure you have just one “Events” folder in your library
(even in the Trash folder).

© 2011 Tim Doyle, timdoyletx at gmail dot com
*)

tell application “Aperture”
activate
set rootFolder to “Events”
set dash to “-“
set spacebarspace to ” | “

tell library 1
set _projects to every project in folder rootFolder
repeat with p from 1 to count of _projects

tell item p of _projects
set projectName to name
end tell
–display dialog “PN=” & projectName

tell current application
if (offset of “|” in projectName) > 0 then
set eventName to text ((offset of “|” in projectName) + 2) thru (length of projectName) of projectName
else
set eventName to projectName
end if
end tell
–display dialog “EN=” & eventName

set _versions to every image version in project projectName
set imageDate to “”
repeat with v from 1 to count of _versions
tell item v of _versions
set thisImageDate to value of EXIF tag “ImageDate”
end tell
if (imageDate = “”) then
set imageDate to thisImageDate
else
if (thisImageDate < imageDate) then
set imageDate to thisImageDate
end if
end if
end repeat

set _tday to day of imageDate as number
if _tday < 10 then
set _day to “0” & (_tday as string)
else
set _day to _tday as string
end if

set _tmonth to month of imageDate as number
if _tmonth < 10 then
set _month to “0” & (_tmonth as string)
else
set _month to _tmonth as string
end if

set _year to year of imageDate as string

set _name to _year & dash & _month & dash & _day & spacebarspace & eventName

–display dialog “Would have renamed ” & projectName & ” to ” & _name
tell project projectName
set name to _name
end tell

end repeat
end tell
end tell

Tim Doyle's picture
by Tim Doyle
February 16, 2012 - 11:32pm

A couple of notes on the usage of this script. Let’s say you have a number of projects variously named, and you’d like to convert them to the name described above. Simply create a folder named “Events” and drag all of the projects you want renamed there, then run this script.

PhotoJoseph's picture
by PhotoJoseph
February 17, 2012 - 9:00am

Tim,

I just tested it and wow that’s cool!

Well done sir :)

@PhotoJoseph
— Have you signed up for the mailing list?

PhotoJoseph's picture
by PhotoJoseph
February 18, 2012 - 8:40am

Tim,

Been playing with your script. Is there any way to

a) have it look inside of subfolders under your top “Events” folder and have it rename those projects as well, and

b) set it so the folder “Events” does NOT have be at the top level? If you could just rename andy project “Events” and run the script and have it find that folder, no matter how deep it is?

@PhotoJoseph
— Have you signed up for the mailing list?

Paul Durbin's picture
by Paul Durbin
July 17, 2012 - 12:25pm

I was so excited to see this script, and ran it successfully twice to rename several dozen projects. I went to run it a third time … but it doesn’t do it. I re-copied the above script, closed and opened Aperture, but it still doesn’t work. I’m so bummed! Any idea why it stopped working for me?

Paul Durbin's picture
by Paul Durbin
July 17, 2012 - 1:18pm

I guess I posted too soon. I discovered that I had two “events” folders. I deleted the one and then the script ran fine. phew!

Tim Doyle's picture
by Tim Doyle
July 17, 2012 - 9:45pm

Paul - I had this same problem when I was working on the script, except my second copy was in the trash - talk about a hard to figure out bug!

Keep in mind that the script uses the folder named Events, but you can always change that - there’s a simple variable being set near the top of the script. Change it to whatever is needed.

Tim

Tim Doyle's picture
by Tim Doyle
July 18, 2012 - 9:52pm

Jim Stackhouse reported a defect in this script - as it looped through the projects in the Events folder, if a project elsewhere in your hierarchy had the same name as one in your Events folder, the script would sometimes modify the wrong folder. The following updated script fixes that defect.

Tim

(*
Rename Aperture Projects

This script loops through each project located within the “Events” folder in Aperture. For each project
found, all photos within are examined, and the oldest photo’s date is used to rename the project to the
format “YYYY-MM-DD | Previous_Project_Name”. This script can be used each time you import, and then
the projects can be moved to other folders. Make sure you have just one “Events” folder in your library
(even in the Trash folder).

© 2011,2012 Tim Doyle, timdoyletx at gmail dot com
*)

tell application “Aperture”
activate
set rootFolder to “Events”
set dash to “-“
set spacebarspace to ” | “

tell library 1
set _projects to every project in folder rootFolder
repeat with p from 1 to count of _projects

tell item p of _projects
set projectName to name
end tell
–display dialog “PN=” & projectName

tell current application
if (offset of “|” in projectName) > 0 then
set eventName to text ((offset of “|” in projectName) + 2) thru (length of projectName) of projectName
else
set eventName to projectName
end if
end tell
–display dialog “EN=” & eventName

set _versions to every image version in item p of _projects
set imageDate to “”
repeat with v from 1 to count of _versions
tell item v of _versions
set thisImageDate to value of EXIF tag “ImageDate”
end tell
if (imageDate = “”) then
set imageDate to thisImageDate
else
if (thisImageDate < imageDate) then
set imageDate to thisImageDate
end if
end if
end repeat

set _tday to day of imageDate as number
if _tday < 10 then
set _day to “0” & (_tday as string)
else
set _day to _tday as string
end if

set _tmonth to month of imageDate as number
if _tmonth < 10 then
set _month to “0” & (_tmonth as string)
else
set _month to _tmonth as string
end if

set _year to year of imageDate as string

set _name to _year & dash & _month & dash & _day & spacebarspace & eventName

–display dialog “Would have renamed ” & projectName & ” to ” & _name
tell item p of _projects
set name to _name
end tell

end repeat
end tell
end tell

Jim Stackhouse's picture
by Jim Stackhouse
July 20, 2012 - 8:04am

Thanks again Tim. The script works great for me now.

Jim

Alex Gorbachev's picture
by Alex Gorbachev
December 16, 2012 - 10:27am

Thanks for the awesome script.

I’ve modified it to ask for the folder name in the dialog (with default being Events).

I’ve also created a Service using Automator for application Aperture. I could have put the script content in the service code itself but instead I saved it in a file and calling this file from the service code. This way I can call the script directly from Aperture using menu Aperture -> Services… -> “my service name”.

I’ve also went to Keyboard shortcut options and assigned this service a shortcut Command-Shift-D (you need to restart Aperture for shortcut to take effect - you will see it in the menu when it’s active) and I can now just press this shortcut, enter folder name if that’s not events and it’s works like a charm.

I’ve also added another feature in the script - I wanted my project name to include last day of the photos in it in case it’s a multi-day project. It will only do that if there are photos for more than one day. Otherwise, the naming is the same. The new naming format I chose is “first_date | project_name <last_date”.

If somebody wants to adopt it or play further, the scripts are below. Sorry Tim for “bastardizing” your script. :)

I also wanted to have the script picking up either current folder or project by default but didn’t get to it (and maybe never will) but it would be cool as I won’t need to enter folder name.

Content of Service script (use your own path to the script - note you use : instead of / in path):

on run {input, parameters}

run script file “SSD:Users:gorby:AppleScripts:FixApertureProjectNames.scpt”

return input
end run

My modified version of the script (or here it’s in PasteBin better formatted - http://pastebin.com/CdU75713):

(*
Rename Aperture Projects

This script loops through each project located within the “Events” folder in Aperture. For each project
found, all photos within are examined, and the oldest photo’s date is used to rename the project to the
format “YYYY-MM-DD | Previous_Project_Name”. This script can be used each time you import, and then
the projects can be moved to other folders. Make sure you have just one “Events” folder in your library
(even in the Trash folder).

© 2011,2012 Tim Doyle, timdoyletx at gmail dot com
– modified by Alex Gorbachev 15-Dec-2012 (folder name dialog + last date addition)
*)

on formatData(_theDate)
set _tday to day of _theDate as number
if _tday < 10 then
set _day to “0” & (_tday as string)
else
set _day to _tday as string
end if

set _tmonth to month of _theDate as number
if _tmonth < 10 then
set _month to “0” & (_tmonth as string)
else
set _month to _tmonth as string
end if

set _year to year of _theDate as string

return _year & “-” & _month & “-” & _day
end formatData

–set rootFolder to display dialog “Enter folder name” default answer “Events”
tell application “Aperture”
activate
set rootFolder to “Events”
display dialog “Enter folder name” default answer rootFolder
set rootFolder to text returned of result

tell library 1
set _projects to every project in folder rootFolder
repeat with p from 1 to count of _projects

tell item p of _projects
set projectName to name
end tell
–display dialog “PN=” & projectName

tell current application
if (offset of “|” in projectName) > 0 then
set eventName to text ((offset of “|” in projectName) + 2) thru (length of projectName) of projectName
else
set eventName to projectName
end if
end tell
–display dialog “EN=” & eventName

set _versions to every image version in item p of _projects
set minImageDate to “”
set maxImageDate to “”
repeat with v from 1 to count of _versions
tell item v of _versions
set thisImageDate to value of EXIF tag “ImageDate”
set thisImageDate to thisImageDate - (time of thisImageDate)
end tell
if (minImageDate = “”) then
set minImageDate to thisImageDate
else
if (thisImageDate < minImageDate) then
set minImageDate to thisImageDate
end if
end if
if (maxImageDate = “”) then
set maxImageDate to thisImageDate
else
if (thisImageDate > maxImageDate) then
set maxImageDate to thisImageDate
end if
end if
end repeat

if minImageDate = maxImageDate then
set _name to formatData(minImageDate) of me & ” | ” & eventName
else
set _name to formatData(minImageDate) of me & ” | ” & eventName & ” <” & formatData(maxImageDate) of me
end if

–display dialog “Would have renamed ” & projectName & ” to ” & _name
tell item p of _projects
set name to _name
end tell

end repeat
end tell
end tell

Alex Gorbachev's picture
by Alex Gorbachev
December 16, 2012 - 11:10am

I’ve introduced a small bug renaming with the last date so if you run it multiple times it would add last date again. Can be fixed by replacing line

set eventName to text ((offset of "|" in projectName) + 2) thru (length of projectName) of projectName

with

set eventName to text ((offset of " | " in projectName) + 3) thru ((offset of " <" in projectName) - 1) of projectName

You may login with either your assigned username or your e-mail address.
Passwords are case-sensitive - Forgot your password?