I've got an applescript that I use to open files such as test.txt in vim, using the terminal.

I usually open a file by right-clicking it an selecting the service open in vim (this service is created by me and basically runs the applescript).

How do I build an actual program, that can be set in the "open with" option for a file?

This way, when I double click test.txt, the applescript gets run and the file gets opened in my vim in terminal.app.

I would also like to create custom icons that will be applied to all files I open using this app (using the "Change All..." button).

Where would I begin? Is this easy, because I'm just a novice -although I love programming and would spend much to to get to know all that is needed to do this.

the code is:

on open this_item

    tell application "System Events"
        if (count (processes whose name is "Terminal")) is 0 then
            tell application "Terminal"
                do script with command "vim " & (POSIX path of this_item) in front window
            end tell
            tell application "Terminal"
                tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
                do script with command "vim " & (POSIX path of this_item) in selected tab of the front window
            end tell
        end if
    end tell

end open

3 Answers 3


Use the built-in AppleScript Editor located in the /Applications/Utilities folder. Then go File>Save As and select Application as the file format. Then, to select the type of file you want it to be opened with, select the file, right click on it and select Get Info. Expand the Open With: tab and choose your applescript application and click on change all.

  • This doesn't work for (believe me I tried). When I open the file after taking these steps they get opened in Applescript Editor
    – romeovs
    May 2, 2011 at 12:12
  • paste the code here and i'll see what i can do.
    – user6124
    May 2, 2011 at 12:44

Two obvious alternatives come to mind from not building the application in Applescript editor.

The first is to use Automator and the Run Applescript action. You may need to play around with the script to get the results you want with Automator but if you can it might open up some more option for your workflow as well.

The other option is to create a Cocoa-Applescipt application in Xcode (what used to be known as Applescript Studio). Using this option is not well documented, but you can find out more here: http://www.macosxautomation.com/applescript/develop/index.html Given what you saying about customisation this is definitely something you should look at. It is sometimes a bit of a hard learning curve because of the lack of documentation, but it is surprising how good an application can be when written in Applescript using this method.

  • actually, the automator app works just fine.. All I need now is a way to change the icon for all files of a certain extension (say .tex).
    – romeovs
    May 3, 2011 at 10:29

I explained how to do this with arbitrary shell scripts in this similar topic on SuperUser.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .