Riffing on my AppleScript to toggle an app between foreground and hidden, and inspired by Daniel Jalkut’s script to toggle multiple Twitter apps, I wanted a way to do something similar with web browsers. I already have a great tool for intelligently detecting which browser I want to use: Choosy.

Choosy lets me set up “rules” and define behaviors which select the best option from my list of browsers, using the full list, just running browsers, or more specific lists based on source and type of the url I’m opening. I just needed to get it onto a hotkey.

Choosy, fortunately, has a url-handler for running different behaviors, which is detailed on the Choosy API page. All you need to do is run this AppleScript in your favorite hotkey-triggered script-launching app:

open location "x-choosy://open//"

Choosy Preference PaneThat will trigger the Choosy popup HUD, which can be navigated by keyboard or mouse, where your full list of browsers shows up in your preferred order. Now, you’re hotkey will do exactly what the settings in Choosy tell it to do. You can have it automatically pick your favorite browser if none are running, or offer you a choice of preferred or all browsers. Personally, if no browser is running, I like the choice of all browsers. I also tell Choosy to automatically pick the running browser with the highest preference level in my settings if more than one are running.

This method works well for all the browsers I’ve tested, but has the annoying side effect of always opening a new tab in Chrome/Chromium. It’s not a big deal to me, but might be a deal breaker if Chrome is your primary browser.

I’m inspired to write a quick tool which takes a list of application names from AppleScript, pops up a Choosy-style HUD and returns the selected app name back to the script. A very simple CocoaDialog kind of thing, but better looking in this specific use case. It would make it possible to do this kind of trick with any type of app, and is basically Daniel’s script on steroids. It’s on my long list of projects to play with, we’ll see what happens.