简体   繁体   English

AppleScript:错误“sh:lame:command not found”编号127

[英]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命令周围添加错误处理。

  • To get the same $PATH that interactive shells see (except additions made in your bash profile), you can invoke eval $(/usr/libexec/path_helper -s); 获得交互式shell看到的相同$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 ,这会导致行为的变化 ,最值得注意的是:
    • process substitution ( <(...) ) is not available 流程替换( <(...) )不可用
    • echo by default accepts no options and interprets escape sequences such as \\n . 默认情况下, echo不接受任何选项并解释转义序列,例如\\n
    • other, subtle changes in behavior; 其他,行为的细微变化; see http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html 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; 你可以通过预先购买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. 到您的命令字符串。
  • The locale is set to the generic "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'到命令字符串中。
  • 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 这并不奇怪,因为创建的shell是一个非交互式 (非登录)shell,但有时通过前置手动加载一个人的配置文件很方便. ~/.bash_profile . ~/.bash_profile to the command string; . ~/.bash_profile到命令字符串; note, however, that this makes your AppleScript less portable. 但请注意,这会降低AppleScript的可移植性。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM