My Automator Workflow fails because it fails to find the git command within the 'Run Shell Script' command? Need help

Solution 1:

Scripts run via Automator use the default search path which usually does not include /usr/local/bin. In your case an easy fix would be to put

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

somewhere at the beginning of the script.

Solution 2:

For a more general solution to the bash environment in automator differing from your own you could simply load your personal bash profile at the first line of the automator bash script:

source ~/.bash_profile

This will make the path and any other environment variables you're used to using available from your automator script.

Solution 3:

I solved the same problem of the same "service" workflows being run on differently configured machines by checking what happens when the terminal starts the shell and eventually adding the following snippet to the top of all my "Run Shell Script" actions:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi
if  [ -f "$HOME"/.profile ]; then
    source "$HOME"/.profile
elif [ -f "$HOME"/.bash_profile ]; then
    source "$HOME"/.bash_profile
elif [ -f "$HOME"/.bashrc ]; then
    source "$HOME"/.bashrc
fi

This covers all the cases I've encountered so far.