I am trying to create an AppleScript with commands below. An issue I am having is there is an error at the third line. I have no problem using the lame
command in the terminal directly. In addition, lame
is not a native Mac utility; I installed it on my own. Does anybody have a solution?
do shell script "cd ~/Downloads"
do shell script "say -f ~/Downloads/RE.txt -o ~/Downloads/recording.aiff"
do shell script "lame -m m ~/Downloads/recording.aiff ~/Downloads/recording.mp3"
-- error "sh: lame: command not found" number 127
do shell script "rm recording.aiff RE.txt"
To complement Paul R's helpful answer:
The thing to note is that do shell script
- regrettably - does NOT see the same $PATH
as shells created by Terminal.app
- a notable absence is /usr/local/bin
.
On my OS X 10.9.3 system, running do shell script "echo $PATH"
yields merely:
/usr/bin:/bin:/usr/sbin:/sbin
There are various ways around this:
Use the full path to executables, as in Paul's solution.
Manually prepend/append /usr/local/bin
, where many non-system executables live, to the $PATH
- worth considering if you invoke multiple executables in a single do shell script
command; e.g.:
do shell script "export PATH=\"/usr/local/bin:$PATH\"
cd ~/Downloads
say -f ~/Downloads/RE.txt -o ~/Downloads/recording.aiff
lame -m m ~/Downloads/recording.aiff ~/Downloads/recording.mp3
rm recording.aiff RE.txt"
Note how the above use a single do shell script
command with multiple commands in a single string - commands can be separated by newlines or, if on the same line, with ;
.
This is more efficient than multiple invocations, though adding error handling both inside the script code and around the do shell script
command is advisable.
$PATH
that interactive shells see (except additions made in your bash profile), you can invoke eval $(/usr/libexec/path_helper -s);
as the first statement in your command string.Other important considerations with do shell script
:
bash
is invoked as sh
, which results in changes in behavior, most notably:
<(...)
) is not available echo
by default accepts no options and interprets escape sequences such as \n
.shopt -uo posix; shopt -u xpg_echo;
to your command string."C"
locale instead of to your system's; to fix that, manually prepend export LANG='" & user locale of (system info) & ".UTF-8'
to your command string.. ~/.bash_profile
to the command string; note, however, that this makes your AppleScript less portable.do shell script
command reference: http://developer.apple.com/library/mac/#technotes/tn2065/_index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With