使用mac automator python脚本

时间:2016-07-04 15:51:15

标签: python macos

首先,我想说我是python和mac OS的新手,通常使用C ++编程并使用Windows。

我要做的是创建一个拖放应用程序,使用python / matplotlib绘制文件中的数据。我使用Mac automator创建了一个Run Shell Script(shell:/ usr / bin / python)应用程序,如果我硬编码文件路径,脚本会按预期运行。但是,我想更改脚本,以便通过将文件拖到应用程序上来运行它。到目前为止,这是我的代码:

#!/usr/bin/python
import sys
import matplotlib.pyplot as plt
# This was code from an example online how to create a main like in C++
if __name == "__main__":
    main()
def main(input, *args, **kwargs):
    # If I hardcode the file name
    filename = '/usr/path/to/file/test.txt'
    # If I try to take the filename as an argument by dragging/dropping
    filename = sys.argv[1:]
    with open(filename) as f:
        # Code to read file and plot

自动贩卖机给我的错误:

Run Shell Script failed - 1 error
    File "<string>", line 13

我试图避免安装外部软件,管理员请求,因此我尝试使用已安装的automator。我需要在shell脚本处理参数之前在自动机中添加一些命令,还是我完全错过了什么?这可以通过使用bash脚本来实现,但我不知道如何做到这一点

0 个答案:

没有答案