Running a shell command inside an AppleScript wrapper from Apple Automator

Hi,
I have a working exiftool command that copies, updates metadata and renames image file stored in one directory into a new directory on a different volume. I’m running this command as a shortcut generated by Apple’s Automator Application.

The present shortcut is fine except when it processes image files that have already been processed. The attempt to create duplicate filenames throws an error that lists all the images that have not been created. This is not a problem as all the other files are processed correctly. However it would be great to be able to trap and present the error message in a better way.

My plan is to run the shell script from within an Applescript which will trap the error and present a more useful message, something along the lines of “37 files were not processed as they already existed in the destination folder”. Hopefully you get the idea.

Here is the fully working shell script that can be run inside an Automator Shortcut. The shortcut starts with the path to the folder selected in the Finder and this path is passed to the shell script by Automator via its output / input between workflow steps.

/usr/local/bin/exiftool -m -r '-XMP:TransmissionReference<Filename' '-copyright<(c)${CreateDate#;DateFmt("%Y")} Simon Knight All rights reserved.' '-XMP:PreservedFilename<Filename' '-XMP:Title<Filename' '-IPTC:ObjectName<Filename' '-FileName<CreateDate' -d /Volumes/Images_Disc_02_Master/TempTestImageUpdated/%Y_%m/%Y_%m_%d_%H%M%S_%%f.%%e "$@"

The first steps in the command set values in the current image file, these steps are followed by -d and the path to the destination folder. Each file is renamed with a date stamp as a prefix e.g. 2025_02_05_103725_originalFileName.Extn. The final clause “$@” appears to be where the shell script fails when run from Applescript. I believe that this clause iterates over the files in the folder.
I have copied this into an Do Applescript section of an Automator shortcut and it looks like this:

on run {input, parameters}
	display dialog "Input is set to : " & input
	--display dialog "parameters is set to : " & parameters
	
	set Mycmd to "/usr/local/bin/exiftool  -m -r '-XMP:TransmissionReference<Filename' '-copyright<©${CreateDate#;DateFmt(\"%Y\")} Simon Knight All rights reserved.' '-XMP:PreservedFilename<Filename' '-XMP:Title<Filename' '-IPTC:ObjectName<Filename' '-FileName<CreateDate' -d /Volumes/Images_Disc_02_Master/TempTestImageUpdated/%Y_%m/%Y_%m_%d_%H%M%S_%%f.%%e '$@' " & input
	
	do shell script (Mycmd)
	--return input
end run

When run the Applescript posts an error stating that it is unable to find the file, followed by the path to the selected folder (please see attached screen shot). Lumix:DCIM:113_PANA is the path to a folder of images on a SD card.
Screenshot 2025-02-05 at 11.00.15

I have experimented with how the “$@” is entered and have tried single quotes, escaped double
quotes and using the Applescript constant ‘quote’ & “$@” & ‘quote’ but unfortunately so far I have been unable to get the script to run.

I have attached my non-working workflow:
Ingest images WIP.workflow.zip (94.2 KB)

Any thoughts ?

It looks like you are trying to use operators for command line arguments ($@), which don’t exist in this context.

Once AppleScript hands off to the shell script via do shell script, the only error it will see is whatever the shell script returns, so you would need to repeat through the input items to get the individual errors. This would extend the processing time, but you only get what ExifTool gives you. Note that the input argument is a list, so you would need to format it (quoted form, POSIX path, etc) to a string of space separated file paths.

Solved it!
As red_menace writes above the input from Automator to the “Do Applescript” is of class list and needs converting to a POSIX path using the following extra lines:

set tfolderpath to POSIX path of input

then tfolderpath is replaces input in the shell command.

It would seem that this conversion to class list does not occur when just using an Automator Do Shell Script which is “a trap for young players” or perhaps Automator does the conversion to POSIX automatically.

I also have found that editing the Applescript inside Automator is next to impossible as some form of very unhelpful Auto Complete operates which destroys anything that is typed and even causes the input cursor to jump to other lines. I realise that Automator is old hat so perhaps I would be better off using its replacement “Shortcuts”.

Thanks for your help.

S