How can I run homebrew from an automation?

The PATH passed to a Run Shell Script action in Automator by default is:

/usr/bin:/bin:/usr/sbin:/sbin

You need to include a PATH statement in the Run Shell Script action and or use fully qualified pathnames for any executables called.

That said, using three separate Run Shell Script actions in this use case makes the first one useless as change directory in the first Run Shell Script action has absolutely no bearing on the subsequent Run Shell Script actions. You should work all the commands into a single Run Shell Script action.

In a single Run Shell Script action you could use the following example shell script code:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
cd "$HOME" || exit
brew update && brew upgrade

As coded, it does the following:

  • The PATH statement includes /usr/local/bin where I'd assume brew is.
  • If the cd command fails the script is stopped.
  • brew upgrade is only executed if brew update succeeds .

That all said, I would just use Terminal normally to perform any brew commands so as to be able to see what is going on.