Actually KM has already highly automated much of what you are asking for.
For Each action using a Finders Selection collection.
- In the Execute a Shell Script action there is an option to pass the script, as stdin, the data in a KM Variable, Clipboard, even text:
- In the Execute Shell Script, directly reference KM Variables:
Even if @peternlewis provided us with a text token for the
%FinderSelection%, it would not work inside of the shell script, since AFAIK shell scripts do NOT support any tokens.
I just wanted to make sure you, and others, are aware of the current support KM provides for shell scripts.