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

17,286

Solution 1

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.

Solution 2

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).

Share:
17,286
Dave Brunker
Author by

Dave Brunker

Updated on June 05, 2022

Comments

  • Dave Brunker
    Dave Brunker about 2 years

    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.

  • Dave Brunker
    Dave Brunker over 11 years
    Can the Mac have more than one Python installed at the same time, like the default and Active State?
  • Dave Brunker
    Dave Brunker over 11 years
    So the only way is to create an app? Where can I find out about using Automator and/or AppleScript Editor with Python?
  • nneonneo
    nneonneo over 11 years
    Yep. As long as the copies are installed to different places (e.g. /System/Library, /Library, /usr), or are different Python versions, they can coexist happily.