Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

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'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

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
share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
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 '11 at 12:12
paste the code here and i'll see what i can do. – user6124 May 2 '11 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: 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.

share|improve this answer
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 '11 at 10:29

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

share|improve this answer

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.