MacOS – Making file associations launch a certain extension, but with a console program

automatorfile extensionsfinderlaunchdmacos

It is possible using the right click menu on "Open With" to get the option to choose an application to open a certain file extension. You can then say "Always Open With This".

That works if the program is packaged as an OS/X bundle (which is actually a directory containing lots of stuff under the hood). But is there an easy way to make it so a regular console program could be used to open it by passing the file path as the first parameter on the command line?

Even if you turn on the "All Applications" it leaves Open grayed out on console programs.

Is this the kind of thing which would require an Automator script of some kind, or is there another way?

Best Answer

Create new application in automator

Locate "Run AppleScript" action and drag it to workflow area

Edit AppleScript:

on run {input, parameters}
    tell application "Terminal"
        activate
        do script with command "[YOUR_SHELL_COMMAND] " & (input as string)
    end tell
end run

Save it and use in "Open With" dialog