简体   繁体   中英

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM