Help With Apple Automator

Started by whirl, April 28, 2017, 09:18:55 AM

Previous topic - Next topic

whirl

Using the following command appears to work fine.

exiftool -m -make="Kodak" -model="Brownie" "$@"

In Automator, I want the option to enter the make rather than hard code it into the script.

I have setup a variable called camera-make but just cannot figure out how to use that in exiftool -m -make="Kodak" -model="Brownie" "$@"

Ian

Stephen Marsh

I have some visuals here:

http://prepression.blogspot.com/2016/12/automator-diy-exiftool-gui-services.html

whirl

Thanks Stephen

Where are you using the variable ?

Ian

whirl

I have managed to get the automator to populate the make part of exiftool -m -make="Kodak" -model="Brownie" "$@"  but now I am stuck trying to get it to add the model as well because it appears that Automator cannot have multiple variables.

Has anyone come up against this

Stephen Marsh

#4
Quote from: whirl on April 28, 2017, 12:40:59 PM
Thanks Stephen

Where are you using the variable ?

Ian

I thought that one could use $1 or $1/ instead of  "$@" to refer to the first variable, however I am not having any luck with Automator passing such a single variable to the script.

Testing the workflow and viewing the results, each step is correct - however the final result is not, which would appear to pinpoint an issue with the script...

I am using:

/usr/local/bin/exiftool -subject='$1' "$@"

However the subject/keyword written is literally $1 and not the actual *value* entered into the variable step! So my syntax is probably wrong

I have also tried /usr/local/bin/exiftool -subject='$1/' "$@" and /usr/local/bin/exiftool -subject='"$1/"' "$@"

If I can get this working for 1 variable, I'll then try using two! One baby step at a time...

I thought that I was onto something with this link, however no joy:

https://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/
https://apple.stackexchange.com/questions/222718/passing-arguments-to-run-shell-script-in-automator


P.S. I had to setup the variable first, then select the input file as the 2nd last step directly feeding into the script, rather than making the file input the first step.

Phil Harvey

I've not done any automator programming myself, but perhaps this will help as an example if you haven't seen it already.

- 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

#6
Hi,

"Run Shell Script" Automator actions only accept text as input, which means that even if you get your variables working in the way you're hoping (which would be very tricky), the shell script won't be able to handle the files that the Service passes to it.

One alternative would be wrapping your shell script in an AppleScript, a bit like this:

1) Create an Automator Service that accepts image files in Finder.app
2) Drag in a Run AppleScript action
3) Code the AppleScript action as follows:


on run {file_list}

set camera_make to text returned of (display dialog "Camera make?" default answer "")
set camera_make to "  -make=" & camera_make

set camera_model to text returned of (display dialog "Camera model?" default answer "")
set camera_model to " -model=" & camera_model


repeat with each_file in file_list
set file_path to (quoted form of POSIX path of ((each_file as alias) as string))
set the_exif to "/usr/local/bin/exiftool -m" & camera_make & camera_model & " " & file_path
do shell script the_exif
end repeat

end run



4) Compile the AppleScript (with the hammer button) to check for errors. Save and close the Automator Service

5) Right-click on any image file (or selected group of files), choose your Service from the Services menu. The metadata will be modified for each image

6) This is the bare bones - it would need a bit of extra work if you wanted it to handle folders, or set a different make and model for each image. As it stands it will also create unmodified copies of the original files in the source folder. The code can be modified to avoid that if you want.

Hope it helps.

EDIT: I was wrong about Run Shell Script actions not accepting files as input - they do. I still think an AppleScript may be the best way of getting the other variables into play, but I'll give a shell script another shot.

whirl

Hubert

Many thanks for helping out on this one and supplying some code.

This will help a great deal and now I can proceed further.

Thank you very much indeed

Hubert


Hubert

Getting OT here, but attached is a quick shot of how an Automator workflow could be set up to combine three variables: one list of files and two text variables.

The tricky bit is working out which actions ignore input from the previous action and which don't.

The workflow produces output like this:

/Users/yourname/Desktop/_11005082.jpg
/Users/yourname/Desktop/_11005083.jpg
/Users/yourname/Desktop/_11005084.jpg
/Users/yourname/Desktop/_11005087.jpg
Kodak
Brownie

This can be passed as input to a Run Shell Script action, but I don't have the first idea how to write a shell script to parse it into a valid ExifTool command.

whirl

Thanks Hubert

That is exactly what I did last night and it worked fine.

I am still deciding on whether to use the automator method or AppleScript. Not sure if one is any better than the other

Stephen Marsh

Thank you Hubert! Shell script and AppleScript are both "inaccessible" to me, so I too appreciate the help. Cheers!

Hubert

Just an update on this. Suppose you have a single folder of files, or a single folder containing nested folders of files, and you want to make identical changes to all of the files (e.g. to add the same camera make and model to all the files).

Using the following AppleScript in the Automator workflow I outlined above will be many times faster, as it only calls ExifTool once.

The Service you create will need to be set to accept Folders in Finder.app.


on run {the_folder}
set camera_make to text returned of (display dialog "Camera make?" default answer "")
set camera_make to "  -make=" & camera_make
set camera_model to text returned of (display dialog "Camera model?" default answer "")
set camera_model to " -model=" & camera_model
set folder_path to (quoted form of POSIX path of ((the_folder as alias) as string))
set the_exif to "/usr/local/bin/exiftool -m" & camera_make & camera_model & " -overwrite_original " & folder_path
do shell script the_exif
end run



On a folder containing 256 files, my original workflow took more than a minute to run. The above version took less than 10 seconds. YMMV depending on the speed of your Mac.

Hope it helps someone!

Hubert

Stephen Marsh

Thanks again Hubert! Yes, that does work much faster.

whirl

Quote from: Hubert on May 01, 2017, 05:36:54 AM
Just an update on this. Suppose you have a single folder of files, or a single folder containing nested folders of files, and you want to make identical changes to all of the files (e.g. to add the same camera make and model to all the files).

Using the following AppleScript in the Automator workflow I outlined above will be many times faster, as it only calls ExifTool once.

The Service you create will need to be set to accept Folders in Finder.app.


on run {the_folder}
set camera_make to text returned of (display dialog "Camera make?" default answer "")
set camera_make to "  -make=" & camera_make
set camera_model to text returned of (display dialog "Camera model?" default answer "")
set camera_model to " -model=" & camera_model
set folder_path to (quoted form of POSIX path of ((the_folder as alias) as string))
set the_exif to "/usr/local/bin/exiftool -m" & camera_make & camera_model & " -overwrite_original " & folder_path
do shell script the_exif
end run



On a folder containing 256 files, my original workflow took more than a minute to run. The above version took less than 10 seconds. YMMV depending on the speed of your Mac.

Hope it helps someone!

Hubert


Hubert.

If you enter two separate words for either the make or model, the script fails but will work on a single word.

Example:
Nikon  <-- This works

Example:
Nikon Coolsmart <-- This Fails


Any thoughts.

Ian