Automator Question

Hello, I am new to the forum.

I have this script below that I use to adjust created and modify dates using a specific file name structure. Specifically the dropbox default structure. YYYY-MM-DD HH.MM.SS

exiftool “-alldates<filename” “-filecreatedate<filename” “-filemodifydate<filename” DIR

I am trying to create a folder action, quick action or application in automator that I can drag and drop files into and it run this script.

My problem is this script asks for a directory (DIR) is there a way in automator to have it reference the directory of the inputed files in the script itself or a way to rewrite the script properly so it references the inputed files as the directory?

Or can I use applescript instead of Shell script?

Any help is appreciated.

Hi. Welcome to MacScripter.

exiftool’s a third-party executable which I don’t have, so the following are things to consider rather definitive answers to your query

The only way I can see to achieve what you want in Automator is to use an AppleScript. Start a “Folder Action” workflow in Automator and select the folder to which you want to attach it. Then add the “Run AppleScript” action and insert this code into it:

on run {input, parameters}
	
	tell application "System Events" to set DIR to POSIX path of container of item 1 of input
	
	set exiftoolCommand to "exiftool \"-alldates<filename\" \"-filecreatedate<filename\" \"-filemodifydate<filename\" " & quoted form of DIR
	do shell script exiftoolCommand
	
end run

This works up to the setting of the exiftool command line, but as I said above, I don’t have exiftool itself, so I haven’t been able to check that the line actually works when executed as a shell script.

A purely AppleScript folder action (ie. not using Automator) would look like this:

on adding folder items to thisFolder after receiving theseItems
	
	set DIR to POSIX path of thisFolder
	
	set exiftoolCommand to "exiftool \"-alldates<filename\" \"-filecreatedate<filename\" \"-filemodifydate<filename\" " & quoted form of DIR
	do shell script exiftoolCommand
	
end adding folder items to

The last time I used Folder Actions, such a script would have to be saved in ~/Library/Scripts/Folder Action Scripts/, which folder would have to be created if it didn’t already exist. I’m not sure what the process is now for attaching a script to a folder. Automator probably does it all for you.

One thing to be aware of with folder actions is that if they make detectable changes to the added files or folders, they’re likely to be retriggered because the system watching the folder is fooled into thinking new items have been added.

Also the word is that third-party command-line tools are subject to Gatekeeper security in Catalina, so you may need to authorise exiftool if you upgrade (and if exiftool works on that system).

And finally, it’s already assumed, since you’re posting to our “Automator” forum, that your question concerns Automator. You’re more likely to grab the attention of someone who knows about using it for folder actions if you give your query a more informative subject line. Something along the lines of “Getting the folder to which a folder action is attached”.

Hope this helps.