Question

I have installed gnu coreutils from macports on osx. This script[1], using various coreutils, works as expected when I launch it from the terminal, but when I launch it using applescript[2] I get an error message [3].

[1] Shell script:

#!/bin/bash
path_to_open=$(gfind | grep -v "~$" | grep -v "#$" | gshuf | ghead -n 1) && open "${path_to_open}"

[2] Applescript:

do shell script "sh ~/x/scripts/script1.sh"

[3] Error message:

error "[script_path]: line 2: gfind: command not found
[script_path]: line 2: gshuf: command not found
[script_path]: line 2: ghead: command not found" number 127

What's the problem here?

Was it helpful?

Solution

Set $PATH in the shell script to include the path to the utilities:

#!/bin/bash
PATH=/opt/local/bin:/opt/local/sbin:$PATH
path_to_open=$(...) && open "${path_to_open}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top