We use a lot of shell utilities installed via Homebrew and called from Applescripts.
Since the shell command run from Applescript doesn’t assume the same relative paths as for a user, many of these aren’t being run from simply calling the command:
but from their path:
But on M1 Macs, Homebrew uses completely different paths for everything, so our existing scripts fail.
https://docs.brew.sh/Installation
We’ve actually had this off an on before with default paths for packages changing, or users having something installed some way other than Homebrew defaults. But we’ve just fixed things on a case-by-case basis.
So I thought I could use a tool like “which” or “path_helper” to find my Homebrew tools for me, and hopefully have an elegant solution that will continue to work if paths change on me again.
In terminal on an M1, either of these will return the path to a Homebrew application:
However, inside a “do shell script,” neither of those works.
Both return:
On an Intel Mac, the “path_helper” one works from a “do shell script.”
The “which” command fails in the same way from inside a “do shell script” on an Intel Mac…
On the Intel, in Terminal I can run:
and it returns:
Yet running
do shell script "/usr/bin/which redis-cli"
still fails.
On the M1, running
in Terminal just returns:
So even if I got it working on Intel, sounds like it’s not going to work on M1.
I should probably just give up and have a function that goes and looks for each Homebrew app at each known path we’ve seen it at and returns the path for wherever it found it.
But I’m very curious what’s going on here, and if there’s any way to use a tool like “which” or “path_helper” to find these tools for the generic case.
Thanks in advance for any help. I realize a lot of you won’t have M1’s to test on, but maybe you can at least help explain how this works/doesn’t work.
EDIT:
I noticed that Apple changed the default shell from bash (or bash emulating sh?) to zsh.
This https://unix.stackexchange.com/questions/22979/path-helper-and-zsh claims that path_helper doesn’t work with zsh.
So I tried:
do shell script "/bin/bash -s <<'EOF'
eval `/usr/libexec/path_helper -s`; which redis-cli
EOF"
But I got the same thing: