Search code examples
bashshellapplescriptexewine

OSX Associate a shell script with a file extension?


I want to associate the .exe file extension with a shell script that launches wine. What is the best way to do this?

From what I've gathered, I need to create an AppleScript that will call wine, but how do I get the name of the input file in the AppleScript? If there is a better way to do this, let me know, but as far as I know this is the best way.


Solution

  • 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" & arguments
    end 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).