Search code examples
shellautomator

Automator passing different variables to a shell script


I try to use automator for renaming multiple files

I got this far:

Automator screenshot

the first variable must be inside the Exiftool command line

in this case I selected 2 files, but that could be 1 or 100 files

how do I make this happen? is it possible to start from array key 1 instead of array key 0 for the filenames?


Solution

  • The standard way to do this is to store $1 in a variable, then use shift to remove it from the argument list, and then use "$@" to get all of the remaining arguments (i.e. the original "$2" "$3" "$4" ...) Something like this:

    RenameTo="$1"
    shift
    echo "New name: $RenameTo"
    echo "files:" "$@"
    

    I'm not sure exactly what you're trying to to with exiftool, so I won't try to give that full command.

    Note that the double-quotes aren't required in zsh, but they make this portable to POSIX-compliant shells. Also, echo isn't a very good way to see what a command would do, because it looses the distinction between spaces within an argument (e.g. spaces in the new name, or within a filename) and spaces between arguments (e.g. between the filenamess in a list of them).