On Jul 24, 2016, at 19:55, Deivy Petrescu <email@hidden> wrote:
So here is a trick so you don’t have to look for the path of all apps
set path2app to (do shell script “whereis the app”
do shell script path2app + rest of command.
`whereis` won't work, because it only looks in the standard directories. (Unless the user foolishly installed a 3rd party app in one of them.)
/usr/bin:/bin:/usr/sbin:/sbin
`which` won't work either, because the AppleScript environment doesn't have anything but the basic path to search.
Again:
/usr/bin:/bin:/usr/sbin:/sbin
The most common directories for 3rd party apps are:
/usr/local/bin/
/opt/local/bin/
I also have some stuff in:
/opt/local/sbin
Hence my:
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;
Which gives me pretty complete coverage in one line.
whereis -- locate programs
The whereis utility checks the standard binary directories for the specified programs, printing out the paths of any it finds.
which -- locate a program file in the user's path
The which utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.
In a do shell script command it is necessary to provide the full path to each 3rd party app, or to adjust the $PATH as I did.
I much prefer to manage the $PATH once, instead of having to enter full paths for every 3rd party app I use in a shell script. (I have a text-expansion for it in Typinator for convenience.)
Another option is loading your ~/.profile or ~/.bashrc files with the source command:
set shCMD to " source ~/.profile echo $PATH " set loginShellPath to do shell script shCMD
I prefer not to do this routinely, because of the potential for unintended side-effects – but that won't stop me when it's the best tool for the job.
It is also possible to call Bash as a log-in shell:
set shCMD to "echo 'echo $PATH' | bash -l" do shell script shCMD
|