Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to launch Python scripts with the mouse in OS-X

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.

like image 451
Dave Brunker Avatar asked Feb 10 '13 00:02

Dave Brunker


2 Answers

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

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

Update:

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.

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

do shell script "/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.

like image 106
Ken Thomases Avatar answered Oct 03 '22 10:10

Ken Thomases


py2app does this with aplomb. You make your Python script, use whatever dependencies you need (wx, Tkinter, etc.) and py2app makes you a standalone app bundle that will run in any modern OS X environment. It bundles Python too, so you can use any Python you want (not just the system default).

The downside is that the generated apps might be large, up to 50MB if you have a lot of dependencies (though that is somewhat of an extreme).

like image 43
nneonneo Avatar answered Oct 03 '22 11:10

nneonneo