Automatically change exported photo timestamps the not-so-elegant way

20130325-automatorI have mentioned in the past that I prefer to keep the file timestamps of photos I export from Aperture in line with the EXIF dates, so that the photo file appears to have been created on the date when the photograph was taken.

I like doing this because many basic tools such as Finder work well with file times and I would rather not fuss around with trying to get tools to read the EXIF times inside the files.

I wanted a totally automatic way of doing this with as little pain as possible, and here’s how I did it:

The Desired Effect

Before going into the details, let me show you the end result:

I go into Aperture, select a whole lot of photos, click Export Version, select my magic Export folder on my Desktop and let ‘er rip.

20130325-export1

Aperture then does its thing and places the files in neat little folders within my Export folder, but all of the dates are wrong. They are all set to Today:

20130325-export2

Then the magic happens, without me even lifting a finger, and all of the dates change to match the photo EXIF dates:

20130325-export3

The Setup

I consider this a hack because I have to use three different tools to do the job: a Folder Action, a shell script, and a command-line image utility.

Download the jhead utility from the developer’s website. Scroll down to the Releases section and download the Pre-built OS-X Intel executable.

Place the downloaded jhead utility in your home directory.

Create a folder called Export on your desktop.

Launch Automator, the robot guy you see at the top of this article.

Choose Folder Actions from the list of options for your new Automator workflow:

20130325-automator2

Construct the workflow thusly:

  • Select the Export folder in the top section, after “Folder Action receives files and folders added to”
  • Add a Run Shell Script action, found in Utilities.
  • Set the Shell to /bin/bash
  • Enter the script shown below
  • Save the workflow as Copy EXIF  to Timestamp

Here is the script:

sleep 5
cd ~/Desktop/Export
find . -type f -name "*.jpg" -exec ~/jhead -ft {} \;

That’s it!

Now go ahead and export some photos to your new Export folder and watch the file timestamps get updated moments after the export completes.

Important Notes

  • The Folder Action is attached to your Export folder only. Don’t try to attach it to a different folder at the same time. Notice that the script has the path to the Export folder hard coded as ~/Desktop/Export. I tried to find a way to make the script smart enough to know which folder triggered the folder action, and I failed.
  • The current script only works with jpeg files; this is because the jhead utility is a utility for jpegs.
  • The script expects a lower-case jpg extension. If you use JPG or jpeg instead of jpg, adjust accordingly.
  • I keep my command line utilities in /usr/local/bin, a traditional place for local additions to a Unix system. This takes a bit more effort, requiring creation of the bin directory on a vanilla OS X system and moving the jhead utility there, both with sudo in the Terminal. Don’t worry about doing all that, just put it in your home directory.
  • Your new folder action lives under ~/Library/Applications/Workflows /Folder Actions. Note that you have to do some trick or another to get at things in Library.

Closing Thoughts

I hope that this slightly inelegant Automator action will be of use to others.

I tried several other approaches but was stymied by some of the odd behaviors in Automator. For example, there is an action that allows you to act on all added files and folders, but when I tried using it I found that when Aperture created a subfolder the action received one event, for the subfolder, and no events as items were added to the subfolder. Stuff like this made me just give in and throw together something that works.

Trust me, once you get it set up it just keeps on working like magic in the background without you ever having to tend to it again.

 

Leave a Reply