为什么这不起作用?
苹果脚本:
set script_path to "$HOME/Desktop"
do shell script "python & script_path & hello_world.py"
Python 脚本:
#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
<head>
<title>Python - Hello World</title>
</head>
<body>
Hello World
</body>
</html>
“”“
错误:
tell current application do shell script "python & script_path & hello_world.py" --> error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 Result: error "sh: script_path: command not found sh: hello_world.py: command not found" number 127
最佳答案
& 符号连接字符串文字和变量替换。就像这样:
set script_path to "$HOME/Desktop"
do shell script "python " & script_path & "/hello_world.py"
您还需要在 hello_world.py 之前或 $HOME/Desktop 末尾添加斜杠。上面的示例将其显示在 hello_world.py 之前。
关于python - 从 Applescript 运行 Python 脚本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16126058/