I have this code to translate a word from/to English/Spanish:
S=`/usr/local/bin/trans -b -id -no-ansi "$a" | grep Code | awk '{print $2}'`
if [ "$S" = "en" ]; then T=es; else T=en; fi
/usr/local/bin/trans -b :"$T" "$a"
(trans
is from https://github.com/soimort/translate-shell/)
Running the script straight in Terminal (bash) works great.
But when I try to use it in Automator, I get this error:
/usr/local/bin/trans: line 5073: gawk: command not found
Running gawk
in Terminal also works fine.
UPDATE: Thanks to solver below, final working script for automator is:
PATH=$PATH:/usr/local/bin
S=`/usr/local/bin/trans -b -id -no-ansi "$@" | grep Code | awk '{print $2}'`
if [ "$S" = "en" ]; then T=es; else T=en; fi
/usr/local/bin/trans -b :"$T" "$@"
Best Answer
The default
PATH
passed to the Run Shell Script action in Automator is:I always add a
PATH=...
, where...
is the actualPATH
used in Terminal, to the top of the Run Shell Script action in Automator.Or you have to add the fully qualified pathname of any executable to the command line that is not in the default
PATH
passed to the Run Shell Script action in Automator.The last line in the
trans
script isgawk -f <(echo -E "$TRANS_PROGRAM") - "$@"
and unlessgawk
is in the defaultPATH
passed you'll need to add the location ofgawk
to thePATH
you pass to the Run Shell Script action in Automator, or add the fully qualified pathname to thegawk
command at the end of thetrans
script.In Terminal use
which gawk
to get its path, e.g.:In
trans
, change:To:
Or in the Run Shell Script action in Automator, e.g.:
Or use the
PATH
from the output ofecho $PATH
in Terminal.