Question
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"
Answer - 1
Probably a
PATH
problem - use the full path for lame. – Paul R May 18 '14 at 13:44
@Paul Oh you are right! usr/local/bin/lame Solved! Thank you so much! – Evan S May 18 '14 at 13:46
You’re welcome - I’ve converted this to an answer now in case anyone comes looking for answers to a similar problem in the future… – Paul R May 18 '14 at 14:50
Answer - 2
Probably a PATH problem - use the full path for lame, e.g.
do shell script "/usr/local/bin/lame -m m ~/Downloads/recording.aiff ~/Downloads/recording.mp3"
Extended question do you know Mac terminal command to rename with a form of “original file name+current_date”? – Evan S May 18 '14 at 17:47
It’s probably best to post that as a new question, as there may be more than one good answer. – Paul R May 18 '14 at 18:24
Thanks for your reply. I got a good solution by creating a new thread. By the way do you know where to learn basic of shellscript programming online? – Evan S May 19 '14 at 1:39
@EvanS: Look at the bottom of this post: stackoverflow.com/a/23668119/45375 – mklement0 May 19 '14 at 3:27
扫描二维码关注公众号,回复: 15719313 查看本文章
Answer - 3
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.
To get the same
$PATH
that interactive shells see (except additions made in your bash profile), you can invokeeval $(/usr/libexec/path_helper -s);
as the first statement in your command string.
Other important considerations with do shell script
:
bash
is invoked assh
, which results in changes in behavior, most notably:process substitution (
<(...)
) is not available
echo
by default accepts no options and interprets escape sequences such as\n
.other, subtle changes in behavior; see http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html
You could address these issues manually by prepending
shopt -uo posix; shopt -u xpg_echo;
to your command string.
The locale is set to the generic
"C"
locale instead of to your system’s; to fix that, manually prependexport LANG='" & user locale of (system info) & ".UTF-8'
to your command string.
No startup files (profiles) are read; this is not surprising, because the shell created is a noninteractive (non-login) shell, but sometimes it’s handy to load one’s profile by manually by prepending
. ~/.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
Answer - 4
I have been struggling to get the path of an installed BASH command via Applescript for a long time. Using the information here, I finally succeeded.
tell me to set sox_path to (do shell script "eval $(/usr/libexec/path_helper -s); which sox")
Answer - 5
Url:http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309
./configure
make install
It looks like you’re trying to post
lame
installation instructions, but the OP’s problem is not that it isn’t installed, it is thatdo shell script
cannot find the installed version. – mklement0 Jun 16 '17 at 19:54