因此,我尝试让Excel电子表格中的一个按钮启动Python脚本。显然,这只在Windows上是可能的,所以在Mac版本中,人们有一个变通方法,他们使用Excel来启动一个AppleScript,然后启动一个Python脚本。
在Automator中,我尝试了选择应用程序,当它不起作用时,我选择了Quick Action,两次我都插入了一个'Run Shell Script‘模块。
在其中,我将Shell设置为“usr/bin/python”,并将输入作为“参数”进行传递。然后在文本字段中输入
do shell script "/Users/user_name/Desktop/integrationtest.py"我试过了
do shell script "python /Users/user_name/Desktop/integrationtest.py"当我单击Automator右上角的Run时,它显示
The action “Run Shell Script” encountered an error: “ File "<string>", line 1
do shell script "/Users/user_name/Desktop/integrationtest.py"
^
SyntaxError: invalid syntax”
File "<string>", line 1
do shell script "/Users/user_name/Desktop/integrationtest.py"
^
SyntaxError: invalid syntax不太确定我做错了什么--有什么想法吗?谢谢你的帮助
发布于 2019-08-20 04:29:53
您混淆了AppleScript和Shell脚本语法。
python /Users/user_name/Desktop/integrationtest.py
在运行{ input,parameters}时执行外壳脚本"python /Users/user_name/Desktop/integrationtest.py“返回输入端运行
发布于 2019-08-20 01:07:19
我建议您一步一步来:首先打开终端应用程序,测试您的python脚本是否运行良好:
python /Users/user_name/Desktop/integrationtest.py如果OK,则打开Applescript编辑器并创建一行脚本:(在Applescript中,某些环境设置可能与通常的bash终端不同)
do shell script "python /Users/user_name/Desktop/integrationtest.py"如果此Applescript测试再次按预期工作,则从Excel调用此Applescript。调用的方法取决于您的Excel版本:对于Excel2011,使用Macscript函数;对于Excel2016,使用ApplescriptTask。
https://stackoverflow.com/questions/57560183
复制相似问题