MacOS – Automator: “Run Shell Script” throws error because of missing “on” command

applescriptautomatorbashmacosterminal

OSX 10.11.4 here.

I'm trying to create a workflow for use with a hotkey, to run a simple shell script.

Created via: Automator -> New Service -> Utilities -> Run Shell Script, then set to 'no input' in 'Finder', and shell set to "/bin/bash".

For a trivial script, say, one containing nothing but "ls", it works.

But I'm only getting errors so far for the script I actually want to run, which includes a call of "on run", which seems to cause problems. After debugging a bit, I can bring it down to this:

on run {input, parameters}

end run

results in error:

Run Shell script failed - 1 error
-: line 2: on: command not found

Might have something to do with a missing path I figured, so I already tried working on that, e.g. by adding:

PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH

or:

PATH=/usr/bin:/usr/local/bin export PATH

as suggested here. Didn't help.

Note as well: I have Anaconda installed, which looks like it changed the path in .bash_profile. Then again, I'm not even sure if the bash environment invoked by automator looks at .bash_profile.

Any ideas what to try next?

Best Answer

on run {input, parameters} is AppleScript syntax, not a valid shell command. If you want to execute AppleScript in the service, use the Run AppleScript action instead of Run Shell Script.