简体   繁体   English

Bash脚本可在终端中使用,但在Applescript中会显示“ python3:找不到命令”

[英]Bash script works in Terminal but in Applescript gives “python3: command not found”

SOLVED: see solution in replies 已解决:请参阅答复中的解决方案

I have a bash script that looks like this: 我有一个bash脚本,如下所示:

#!/bin/bash
python3 /Users/me/path/to/my/file.py
python3 /Users/me/path/to/my/file2.py
Rscript /Users/me/path/to/my/rfile.R
python3 /Users/me/path/to/my/file.py

When I execute it from terminal with the command 当我使用命令从终端执行它时

bash /Users/me/path/to/my/shellscript.sh

it executes perfectly. 它执行完美。 However, I would like to be able to run it from Keyboard Maestro or AppleScript. 但是,我希望能够从Keyboard Maestro或AppleScript运行它。 In AppleScript, when I run 在AppleScript中,当我运行时

do shell script "bash /Users/me/path/to/my/shellscript.sh"

I get the following error message: 我收到以下错误消息:

error "/Users/me/path/to/my/shellscript.sh: line 2: python3: command not found
/Users/me/path/to/my/shellscript.sh: line 3: python3: command not found
/Users/me/path/to/my/shellscript.sh: line 4: Rscript: command not found
/Users/me/path/to/my/shellscript.sh: line 5: python3: command not found" number 127

I receive the same error message if I run the equivalent command in Keyboard Maestro. 如果我在Keyboard Maestro中运行等效命令,则会收到相同的错误消息。 I have tried changing python3 to python , but it fails anyway because it runs the files in Python 2 (despite the shebang of the Python files specifying Python 3), and the Rscript command would surely still throw an error. 我尝试将python3更改为python ,但是无论如何还是失败了,因为它在Python 2中运行文件(尽管Python文件指定了Python 3,但Rscript命令肯定仍会引发错误。

What is the difference between the environments that causes the shell script to fail in Keyboard Maestro and AppleScript but not Terminal? 导致Shell脚本在Keyboard Maestro和AppleScript中失败而不在Terminal中失败的环境之间有什么区别?

I got it to work by changing the command to PATH=$PATH:/usr/local/bin; bash /Users/me/path/to/my/shellscript.sh 我通过将命令更改为PATH=$PATH:/usr/local/bin; bash /Users/me/path/to/my/shellscript.sh PATH=$PATH:/usr/local/bin; bash /Users/me/path/to/my/shellscript.sh . PATH=$PATH:/usr/local/bin; bash /Users/me/path/to/my/shellscript.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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