OSX Associate a shell script with a file extension? OSX Associate a shell script with a file extension? shell shell

OSX Associate a shell script with a file extension?


You can also use Automator to wrap your own bash, python or ruby script in an "Application".

  1. Open Automator and choose to create an Application.

  2. Find the Action "Run Shell Script" and double-click it or drag it to the script area.

  3. Select the interpreter you want (bash, other shells, python or ruby).

  4. Set the "Pass input" option to "as arguments". (In the automator model, the application "receives files and folders as input"; hence this lets your script see filenames as commandline arguments).

  5. Enter your shell script in the edit area. On bash, use "$@" for the list of commandline arguments (individually quoted to protect embedded spaces).

You can now save the script (it will get a .app extension), and move it to the Applications folder or other reasonable location. It can be associated with a file type, like any other application.

NOTE: This works on Mountain Lion (10.8); can someone comment on how long Automator has been able to do this?


You can use an AppleScript application to do this - files are passed to the open handler, the same as a droplet, for example:

on open theFiles    set arguments to ""    repeat with anItem in theFiles        set arguments to arguments & space & (quoted form of POSIX path of anItem)    end repeat    do shell script "/path/to/wine" & argumentsend open

To associate a particular document type with your application, you will first need to add information to your application's information property list (Info.plist) to tell Launch Services what types of documents it can handle. See Apple's Document-Based Applications Overview (or take a look at the settings in other applications).