Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to figure out if it's possible to program the open action (double clicking on a file) for a given file extension in OS X as:

Pass the file's absolute path to a shell script (bash or ruby or python preferably).

The only solution I'm arriving at is packaging my script as an app and setting the filetype association to always open extension .xyz in my app. Is there an easier way?

share|improve this question

migrated from Jul 17 '10 at 12:16

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

The only way is to package the script as an app.

For portability, you can simply create an AppleScript container that will execute the shell script you created.

Check out do shell script for more information.

When you go to save the script, be sure to save it as an "Application" or "Application Bundle".

share|improve this answer
good call, didn't think of that. i think this'll work for now. – Trevor Hartman Jul 23 '09 at 21:37
oh, one other thing: know how to grab the path of the file that was opened in the applescript app? – Trevor Hartman Jul 23 '09 at 21:51

I had tons of problems with the pure-AppleScript approach. Then I found Platypus - it had me up and running in less than 5 minutes.

share|improve this answer

You should be able to right click a file and "Get Info". Under "Open with" you can select the script you want to open the filetype with and also check the "Change All" button.

This should change the filetype to open with your script.

share|improve this answer
I realize that's how you normally change associations with apps – Trevor Hartman Jul 23 '09 at 21:15
but it doesn't work with scripts. Only fully packaged apps. – Trevor Hartman Jul 23 '09 at 21:15
  • Right-click on a file of the file type in question;
  • Go to "open with";
  • Pick the program;
  • And then click "Change All.."
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .