osx: launching a shell script containing gnu coreutils commands, works via terminal, not via applescript

StackOverflow https://stackoverflow.com/questions/17384416

Вопрос

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?

Это было полезно?

Решение

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}"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top