Set default open-with app to a Python program on a Mac

All we need is an easy explanation of the problem, so here it is.

I use the open source application UliPad to edit restructured text files (rst). It is a Python application that I launch via Terminal like so:

python32 UliPad.py

I have python32 as an alias to the 32bit install of Python on my machine. I have several versions installed.

First I would like a way to launch UliPad like other OS X apps. Not really sure how to do this.

Secondly, I would like to set all .rst files to be opened with UliPad.py. Is there a way to do this? I know how to choose the default app in Finder but not sure how to choose UliPad as that app.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

For your second question, according to How to associate the “.exe” extension to be opened with Mono?, you need an .app bundle:

Apparently, when using Finder’s GUI, only .app files (application bundles) can be selected.

If that’s true for Python scripts as well, then my answer at that question might help, with for Step 5:

5. Replace echo "$f" with python32 UliPad.py "$f"

So, in short, create an Automator “application” to run the following Shell script:

PYTHON=/Library/Frameworks/Python.framework/Versions/6.1/bin/python/
ULIPAD=/Users/vmd/Dropbox/Ulipad/UliPad.py
if [ $# -eq 0 ]
then
  # No parameters passed; just run it without any files:
  $PYTHON $ULIPAD
else
  # Run an instance for each file:
  for f in "[email protected]"
  do
    $PYTHON $ULIPAD "$f"
  done
fi

…or maybe you can pass multiple files to UliPad.py in one go:

PYTHON=/Library/Frameworks/Python.framework/Versions/6.1/bin/python/
ULIPAD=/Users/vmd/Dropbox/Ulipad/UliPad.py
$PYTHON $ULIPAD "[email protected]"

As for your first question: you should be able to use the same Automator “application” to just start UliPad without opening any file (if indeed you then just need to run it without any parameters, like I assumed above).

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply