user3595091
user3595091

Reputation: 11

passing multiple parameters to a shell script from Automator

forgive a newbie question.I have searched high and low but not found a similar situation.

I'm trying to create an automatic process where I can add keywords to jpg images.

I'm using Hazel to monitor a folder on my Mac and when it finds a file, it calls an Automator workflow script. Thus the script already receives one parameter (filename and path)

The shell script executes the following (using pass input: as arguments) (shell: /bin/bash)

for f in "$@"
do
    exiftool -keywords=myKeyWord "$1"
    exiftool -delete_original! "$1"
done

So far everything works. What I can't figure out is how to pass a second parameter from Automator that will allow me to input a keyword from a dialog box.

I have tried to a text field (Action: Ask for Text), and update the hardcoded value 'myKeyWord' with "$2", but it gives me an error stating "1 files weren't updated due to errors"

Any help would be greatly appreciated.

Thanks in advance,

Thomas

Upvotes: 1

Views: 2524

Answers (1)

Scrutinizer
Scrutinizer

Reputation: 9936

The loop is iterated for every parameter to the script. However, within the loop only the first parameter is being used: $1 instead of $f . So if you call the script with say 3 parameters it does the following:

exiftool -keywords=myKeyWord "$1"
exiftool -delete_original! "$1"
exiftool -keywords=myKeyWord "$1"
exiftool -delete_original! "$1"
exiftool -keywords=myKeyWord "$1"
exiftool -delete_original! "$1"

Perhaps you mean to do something like this (without a loop)? Just guessing :

exiftool -keywords="$2" "$1"
exiftool -delete_original! "$1"

Upvotes: 1

Related Questions