MacOS – How to make a simple app from an applescript!

applescriptmacos

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"
                activate
                do script with command "vim " & (POSIX path of this_item) in front window
            end tell
        else
            tell application "Terminal"
                activate
                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

Best Answer

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.