[英]AppleScript : error “sh: lame: command not found” number 127
I am trying to create an AppleScript with commands below. 我正在尝试使用以下命令创建AppleScript。 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. 我没有问题直接在终端中使用
lame
命令。 In addition, lame
is not a native Mac utility; 另外,
lame
不是原生的Mac实用程序; 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 : 补充Paul R的有用答案 :
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
. 需要注意的是,
do shell script
- 遗憾的是 - 看不到与Terminal.app
创建的shell相同的$PATH
- 值得注意的缺席是/usr/local/bin
。
On my OS X 10.9.3 system, running do shell script "echo $PATH"
yields merely: 在我的OS X 10.9.3系统上,运行
do shell script "echo $PATH"
仅产生:
/usr/bin:/bin:/usr/sbin:/sbin
There are various ways around this : 有各种方法 :
Use the full path to executables , as in Paul's solution. 使用 Paul的解决方案中的可执行文件的完整路径 。
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; 手动将许多非系统可执行文件所在的
/usr/local/bin
附加/追加到$PATH
- 如果在单个do shell script
命令中调用多个可执行文件,则值得考虑; eg: 例如:
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 ;
注意上面如何在单个字符串中使用带有多个命令的单个
do shell script
命令 - 命令可以用换行符分隔,或者如果在同一行上,则用;
. 。
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. 这比多次调用更有效,但建议在脚本代码内部和
do shell script
命令周围添加错误处理。
$PATH
that interactive shells see (except additions made in your bash profile), you can invoke eval $(/usr/libexec/path_helper -s);
$PATH
(除了在bash配置文件中添加的内容),您可以调用eval $(/usr/libexec/path_helper -s);
as the first statement in your command string. Other important considerations with do shell script
: 使用
do shell script
其他重要注意事项 :
bash
is invoked as sh
, which results in changes in behavior , most notably: bash
被调用为sh
,这会导致行为的变化 ,最值得注意的是:
<(...)
) is not available <(...)
)不可用 echo
by default accepts no options and interprets escape sequences such as \\n
. echo
不接受任何选项并解释转义序列,例如\\n
。 shopt -uo posix; shopt -u xpg_echo;
shopt -uo posix; shopt -u xpg_echo;
手动解决这些问题shopt -uo posix; shopt -u xpg_echo;
shopt -uo posix; shopt -u xpg_echo;
to your command string. "C"
locale instead of to your system's; "C"
语言环境而不是系统的语言环境 ; to fix that, manually prepend export LANG='" & user locale of (system info) & ".UTF-8'
to your command string. export LANG='" & user locale of (system info) & ".UTF-8'
到命令字符串中。 . ~/.bash_profile
. ~/.bash_profile
. ~/.bash_profile
to the command string; . ~/.bash_profile
到命令字符串; note, however, that this makes your AppleScript less portable. do shell script
command reference: http://developer.apple.com/library/mac/#technotes/tn2065/_index.html do shell script
命令参考: http : //developer.apple.com/library/mac/#technotes/tn2065/_index.html
可能是一个PATH
问题 - 使用跛足的完整路径,例如
do shell script "/usr/local/bin/lame -m m ~/Downloads/recording.aiff ~/Downloads/recording.mp3"
I have been struggling to get the path of an installed BASH command via Applescript for a long time. 我一直在努力通过Applescript获得已安装的BASH命令的路径很长一段时间。 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")
Thanks. 谢谢。
Url:http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309
./configure
make install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.