MacOS – How to bind a multitouch gesture to open a file with a particular application

bettertouchtoolmacmacosmulti-touchtrackpad

I am running Mac OS X Lion. What I want is a way to open an HTML file with a particular application based on my action.

For example, the default application is Safari, so it will always open in Safari if double clicked. However, I want to add another gesture, (such as tapping on middle top of the trackpad) while the file has been selected (highlighted), such that it will open in TextWrangler.

Is it possible? I am also using BetterTouchTool.

Best Answer

Use this AppleScript to open a file with a particular application:

set appPath to path to application "TextWrangler"
tell application "Finder"
    set sel to selection
    if sel is not {} then
        set filepath to item 1 of sel as text --> The path to the one selected item.
        open file filepath using appPath
    end if
end tell

I've never used BetterTouchTool but according to the documentation, you can set up any input (such as a three-finger tap) to run an arbitrary AppleScript if it's saved as a scpt file.

Open the AppleScript Editor, copy and paste the code above, and save it as opentw.scpt or something similar. Then in BetterTouchTool, add a new gesture. Choose three-finger tap as the gesture, and choose the Predefined Action of Open Application/File/Script. Locate the AppleScript file you saved above as the script to open.