Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'd like to be able on OS X (Mountain Lion) to automatically open a file with a custom command. In particular, if I double-click on file xxx.vcb, I'd like it to open with:

python xxx.vcb

in a terminal window - and more specifically, in iTerm. Google searches haven't yielded up anything for me. Is it possible?

share|improve this question
up vote 2 down vote accepted

You can basically do anything with the Open with… menu as long as you know how to use AppleScript and Automator.

Open up from Applications, and create a new Application. From the left, drag Run AppleScript to the right pane, and here, paste the following:

on run {input}
    set filepath to quoted form of POSIX path of input
    tell application "iTerm"
        make new terminal
        tell the current terminal
            activate current session
            launch session "Default Session"
            tell the last session
                write text "python " & filepath
            end tell
        end tell
    end tell
    return input
end run

Like this:

As you can see, the code will first create the POSIX-compatible path from the input file you opened the app with. It needs to be quoted in case the path contains spaces. Then, we'll tell iTerm to open, create a new tab, then write the command as text to the console.

Save this as an application, and use this to open your file with. To do that, right-click on the file you want to use your new app with, click Get Info, and under Open With » Other…, select your new app – note that I chose an HTML file here, but it doesn't matter which type. Make sure to tick Always Open With if you want it to be applied for all files of that type.

Now, double-click the file, and there you go:

share|improve this answer
Ehhxcellent. Thank you very much. I must learn AppleScript. – Tony Aug 5 '12 at 1:14

Your Answer


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.