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.

  • See this. Aug 23, 2013 at 22:59
  • Thanks. But I am not able to understand it. What is automators services? Aug 23, 2013 at 23:00
  • @sameetandpotatoes He want a gesture not a keyboard shortcut (as far as I can tell).
    – daviesgeek
    Aug 23, 2013 at 23:02
  • Yeah but if a keyboard shortcut is available, I can map it to a gesture through BTT, so that won't be a problem.. Aug 23, 2013 at 23:03
  • Ah, very true. I forgot about that…
    – daviesgeek
    Aug 23, 2013 at 23:16

2 Answers 2


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.

  • Umm, how do I tell which shortcut to use to open in which app? My BTT specs specify that a four finger tap will map to opening it with the default app (in this case, Safari). How do I specify another shortcut, say 3 finger tap to open this with Textwrangler? Aug 23, 2013 at 23:11
  • I added some info to the answer. I don't have BetterTouchTool to play with but I used their website to figure out the approximate steps.
    – tubedogg
    Aug 23, 2013 at 23:24
  • Will try it..But where did you specify those files ending with .html? Aug 23, 2013 at 23:31
  • I didn't. You asked how to open the currently selected file, in TextWrangler, which is what my steps give you. :) It could be fairly easily modified to switch the application used based on the file extension but you'd need a pre-defined list of applications and the associated extensions you want to open in them.
    – tubedogg
    Aug 23, 2013 at 23:33
  • Okay, I am fine with that too. So with this, if I choose any file (say HTML), and do a three-finger tap, it will be opened in Textwrangler, right? Aug 23, 2013 at 23:37

You can run an AppleScript file using BetterTouchTool, but I don't know how you get the selected file. Here's the script:

tell app "<your application here>" to open file <file here>

That will work as long as there's an application to open and a file to open. The problem is getting the selected file...

You must log in to answer this question.

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