Running Grunt from OSX Automator shell script Running Grunt from OSX Automator shell script shell shell

Running Grunt from OSX Automator shell script


The problem is that the $PATH variable when running from Automator doesn't have the same entries as when running from Terminal.

Notably, /usr/local/bin is missing, which is where grunt is typically installed (if installed globally).

A simple workaround is to add the folder in which grunt is installed to your $PATH at the top of the Automator shell script:

PATH="/usr/local/bin:$PATH"~/Public/Sites/Launcher.sh

Aside from that:

  • Your shell command, $(grunt serve --open), should be just grunt serve --open - no need for a command substitution ($(...) or `...`), as that would actually first execute the command and then try to execute the output from that command.

  • The default working dir. when running a shell script from Automator is ~ (your home folder), which may not be what your script expects; it looks like your script expects its own dir. to be the working dir., so use cd ~/Public/Sites && ./launcher.sh to invoke it.

  • Automator will report an error in case the shell script exits with a nonzero exit code; the error message will include the shell script's stderr output (and nothing else) - sounds like no stderr output is being produced in your case.

    • To capture all output for diagnostic purposes, use something like ./launcher.sh &> ~/log

On macOS 10.11 through at least 10.15 (as of this update), $PATH has the following value inside a shell script run from an Automator workflow: /usr/bin:/bin:/usr/sbin:/sbin