Editing version names and other news

Since I put this site up I have had a few people ask me for assistance with a script they are writing to automate Aperture. First, let me say I'm happy to hear users of Aperture are interested in automating Aperture as well as find this web site useful. And secondly, I am happy to help improve the content of this site using reader feedback.

A while ago I received a request for help from a reader/user that wanted to change an image version's Exif Image Date by 2 minutes. After thinking about the solution of his problem I realized that this script is far more useful than changing the Exif Image Date by 3 years. So I decided to remove my time shift script on the Metadata page that incremented the image date by 3 years with a script that will add 1 hour to the image date. Why not 2 minutes? Because I want to not only illustrate how to time shift but also provide a useful script to a wider audience. I assume more people will want to change their images' date in increments of an hour to deal with daylight savings time or a change in time zones than will want to change the minute or second. Either way, the modification required is very slight.

Another reader/user recently asked me a question concerning a script he was writing that will remove the file extension from the name of the image version. I thought it was strange that Aperture somehow placed the file extension in the image version name. After playing around with Batch Change, I realized if you change the image version name to the master filename, the images will be named something like: filename.cr2

Since some users of Aperture may see this as a problem and it can be created within the GUI of Aperture, I decided to a script that will get a selection of images and remove a file extension from the version name. You will need to modify the script so that it finds the particular file extension you want found. For those that may not realize where to change the script to handle your individual needs, I left a comment just below the line that should be modified. Enjoy.

Click to open example in the Script Editor applicationRemove file extension from the version name.

 tell application "Aperture"
 set imgSel to (get selection)
 end tell

 if imgSel is {} then
 
error "Please select an image."
 
else

  repeat with i from 1 to count of imgSel
 
set imgName to name of item i of imgSel
 
set newimgName to findAndReplace(".CR2", "", imgName)
 
--Replace .CR2 with the string you want to remove.

 
tell application "Aperture"
 
tell item i of imgSel
 
set name to newimgName
 
end tell
 
end tell
 
end repeat
 
end if

 
on findAndReplace(tofind, toreplace, TheString)
 
set ditd to text item delimiters
 
set text item delimiters to tofind
 
set textItems to text items of TheString
 
set text item delimiters to toreplace
 
if (class of TheString is string) then
 
set res to textItems as string
 
else -- if (class of TheString is Unicode text) then
 
set res to textItems as Unicode text
 
end if
 
set text item delimiters to ditd
  return res
 
end findAndReplace


DISCLAIMER: I outright stole the find and replace function from Nigel Garvey which was posted a forum post on MacScripter. Since it was posted on a forum of a site devoted to learning AppleScript and this site does not collection money, I assumed I was ok to posted the function here.