在 OS-X 中使用鼠标启动 Python 脚本的简单方法 [英] Easy way to launch Python scripts with the mouse in OS-X

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

问题描述

我想编写作为命令行程序的 GUI 前端的跨平台 Python 脚本.问题是我认识一些 Mac 用户,他们认为使用终端与将计算机从摩天大楼顶部扔下的效果相同.在 Linux 和 Windows 中,设置 Python 脚本非常容易,因此用户可以双击图标,脚本将在不打开任何额外窗口的情况下启动.有没有一种简单的方法可以用 OS-X 做到这一点?用户是否必须安装与 OS-X 附带的 Python 不同的 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,选择Application模板,在搜索栏中输入script",双击Run Shell Script,将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,启动 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天全站免登陆