Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Jul 17 '10 at 12:16

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

4 Answers 4

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.