AppleScript "do shell script" ignores PATH Variable

android, applescript, macos, xamarin

Solution

When you invoke bash as an interactive login shell, the paths in `/etc/paths` and `/etc/paths.d/*` are added to `PATH` by `/usr/libexec/path_helper`, which is run from `/etc/profile`. `do shell script` invokes bash as sh and as a non-interactive non-login shell, which does not read `/etc/profile`.

You can run path_helper manually though:

do shell script "eval `/usr/libexec/path_helper -s`; echo $PATH"

Problem

I'm trying to build an automated build script with applescript on MacOS X. For now everything works correctly with one glitch. The command "do script ("zipalign -f -v 4 /tmp/src.apk /tmp/tgt.apk") works fine if I run it in a separate tell for application "Terminal" but leaves the terminal window open when it's done. Everything else in the script works fine in tells for application "Finder". If I try to run the command via "do shell script" inside the tell for "Finder" I only get an error "command not found". The path to zipalign is set in /etc/paths and is reachable through any terminal window and "do shell" but not to "do shell script" command. What is the correct way to ensure that "do shell script" uses $PATH to find commands or alternatively is there a bulletproof way to close the terminal left by "do script"?

Original source