Updating modified date with Hazel or Automator

Started by geaux, April 12, 2018, 11:35:01 AM

Previous topic - Next topic

geaux

Apologies if this has been posted elsewhere.  After exporting files from Photos (Mac), the created and modified file dates no longer reflect the correct dates stored in the EXIF data.  I have been successful updating this in Terminal using:

exiftool "-filemodifydate<datetimeoriginal" FILE

However, I would like to create a Hazel or Automator script that will automatically covert the date when the file is added to the folder, but those applications will not recognize this command as written.  I've tried running both AppleScript and shell script, along with similar looking scripts from other posts, but no luck.  Admittedly, my scripting knowledge is very limited, so I appreciate your guidance.

Phil Harvey

This is really a Hazel or Automator question, but I suspect the problem is one of the following.

1. Problem with quoting of arguments

2. ExifTool isn't in the default path

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Hubert

I don't know about Hazel, but any AppleScript (whether run from Automator or independently) must specify the path where exiftool is installed. By default this is:

/usr/local/bin/exiftool

so a the structure of a very basic AppleScript to run a Shell command would be

do shell script "/usr/local/bin/exiftool options FILE_PATH"

It's quite fiddly getting the quoting right, but it does work with concentration and care!

Hubert

Just to add to my previous post (and hopefully not straying too far away from Exiftool): what you want to achieve is certainly possible.

But from personal experience I would suggest that you use a standalone AppleScript folder action script, and not an Automator folder action as a wrapper for a "Run AppleScript" or "Run Shell Script" action.

The reason for this is that this type of Automator folder action is almost impossible to debug. There is no means of error checking or handling: if there's anything wrong with the shell script or AppleScript, then basically nothing happens, and you have no way of finding out why. As you've already discovered...  ;)

I have written AppleScript folder actions that run Exiftool commands which write copyright, artist and lens data (using 'legacy' lenses on a digital camera) to image files added to a "watched" folder. The files are updated and then automatically imported into Photos.

Let me know if you would like any help writing an AppleScript solution.

Stephen Marsh

#4
Hi geaux,

Here is a quick Automator + ExifTool combo. There may be better ways, this was just the first thing that I quickly knocked up...

There is a source folder on my desktop titled "Test" and within this are two sub-folders, "Input" and "Output".

> Test
>> Input
>> Output

(we need to have a separate output folder to the input folder, otherwise the output will repeatedly loop into the input)


I have attached a screenshot of the automator workflow.

The shell script (bin/bash) has input passed as arguments:

/usr/local/bin/exiftool -filemodifydate<datetimeoriginal -directory="$HOME/Desktop/Test/Output" -r "$@"


I have shortened the output path by using the $HOME variable to the current user's Desktop/Test/Output folder, notice how one has to use double quotes around the entire path, when the Mac would usually use single quotes for a regular path may that contain a word space. You could just use a regular absolute path without the variable. Also note the variable for the input folder used in the Automator Folder Action (again, double quotes around the "$@")

I have added some optional workflow steps to move the input files to the trash, this could be done in many ways.

I hope that this gives you some ideas.