MacOS – Execute Shell Scrip individually for each selected file in Finder

automatorfindermacmacosscript

I am trying to create an automator workflow that will do a google search for the filename of each selected file in finder.

Unfortunately the workflow I have created works just with one selected file. If I select multiple files it doesn't work.

How can I set the Shell Scrip to be executed individually for each selected file in Finder?

Screenshot of Automator Workflow

I have used a custom 'Get Names of Finder Items' Automator Action downloaded from here.

Best Answer

Use a shell script such as the following that will run the command each time for each of the arguments:

for f in "$@"
do
  open "http://www.google.com/search?q=$f"
done