在OS-X中使用鼠标轻松启动Python脚本 [英] Easy way to launch Python scripts with the mouse in OS-X

查看:134
本文介绍了在OS-X中使用鼠标轻松启动Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写跨平台Python脚本,它们是命令行程序的GUI前端。问题是我知道一些Mac用户认为使用终端将具有相同的效果,把他们的计算机从摩天大楼的顶部。在Linux和Windows中,设置Python脚本是很容易的,因此用户可以双击图标,脚本将在不打开任何额外窗口的情况下启动。有一个简单的方法来做到这一点与OS-X?用户必须安装不同于OS-X附带的Python吗?我没有找到一个确定的答案。

I'd like to write cross platform Python scripts that are GUI frontends for command line programs. The problem is I know a few Mac users who think that using the terminal will have the same effect as throwing their computer off the top of a skyscraper. In Linux and Windows it's easy enough to setup a Python script so the user can double click an icon and the script will start without opening any extra windows. Is there an easy way to do this with OS-X? Would the user have to install a different Python than the one that comes with OS-X? I haven't been able to find a definitive answer.

推荐答案

您可能需要查看 Platypus 。它是一个免费应用程序,用于生成包装脚本的应用程序。

You might want to look at Platypus. It's a freeware app for generating apps which wrap scripts.

另一种方法是使用Automator或甚至是AppleScript编辑器。

Another way to do something like that is using Automator or even AppleScript Editor. Either can produce an application which just runs a script.

更新:

对于Automator:启动Automator,请选择应用程序模板,在搜索字段中键入脚本,双击运行Shell脚本,将shell弹出菜单切换到 / usr / bin / python 将您的Python脚本粘贴到文本字段中。或者,保留 / bin / bash 上的弹出菜单,并在文本字段中写入一个外部脚本的调用。保存为应用程序。

For Automator: Launch Automator, select the Application template, type "script" in the search field, double-click Run Shell Script, switch the shell pop-up menu to /usr/bin/python, type/paste your Python script into the text field. Or, leave the pop-menu on /bin/bash and just write an invocation of an external script in the text field. Save as an application.

您也可以从其帮助菜单查看帮助。

You can also view help from its Help menu.

对于AppleScript,编辑器,键入以下脚本作为脚本:

For AppleScript, launch AppleScript Editor, type the following as the script:

do shell script "/usr/bin/true"

使用任何脚本的路径替换 / usr / bin / true 喜欢。另存为应用程序。

Replace /usr/bin/true with the path to whatever script you like. Save as an application.

此外,帮助菜单中还有帮助。

Again, there's help in the Help menu.

这篇关于在OS-X中使用鼠标轻松启动Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆