【发布时间】:2022-01-26 01:04:58
【问题描述】:
我是 AppleScript 的新手:我刚刚创建了一个 AppleScript 来执行我的 python 代码,但是当我执行 AppleScript 时出现“syntaxerror: Invalid syntax”。如果我直接从终端执行它,我的 python 脚本就可以工作。我错过了什么?这是我的代码的前几行 - 错误是由代码的第 2 行触发的:
ipaddr = '192.168.2.254'
stream = os.popen(f'ping -c 4 {ipaddr}')
output = stream.read()
if '0 received' in output:
print('Tunnel is down. Likely due to a network issue. Please contact Admin')
【问题讨论】:
-
你能分享完整的错误吗?
-
快速猜测 - 你安装了多个 python 版本,当你尝试从 AppleScript 运行它时,它会执行一个过程,其中 $PATH 中存在支持 f-strings 的旧 python 版本
-
告诉当前应用程序执行 shell script "python $HOME/Desktop/Tunnel.to.SF/Rosie.py -d" --> error " File \"/Users/jd/Desktop/Tunnel. to.SF/Rosie.py\",第 19 行 stream = os.popen(f'ping -c 4 {ipaddr}') ^ SyntaxError: invalid syntax" number 1
-
@Mureinik 系统默认为 Python3 - 但是我没有删除 python2。我的脚本默认使用 Python3 执行
标签: python-3.x macos applescript