Between Many Tricks and this blog, I spend a lot of time in browsers. Most of the time, I use Safari, but I do occasionally work in Chrome and Firefox, too—most often to check how a page looks or functions.
I keep my "permanent" bookmarks in Safari, and don't presently use any sort of cross-browser sync. (I used to use one, but had a lot of trouble with duplicates, so I stopped.)
I wanted a way to open a limited number of URLs in either Safari (if that's what I was in, or if I wasn't in a browser), or in the frontmost browser, if that browser were frontmost. I could just create the subset as bookmarks in each browser, but if I wanted to add or remove a page from the list, I'd have to do so multiple times.
In the end, I came up with a set of Keyboard Maestro macros that do exactly what I want. I access my short list of multi-browser URLs via Keyboard Maestro's pop-up palette, as seen at right.
This appears when I press ⌃1; after that, a single digit opens the desired URL. But how does it know whether to open the URL in Safari or one of the other browsers? It takes one helper macro, then one macro for each URL that I want to open in this manner.
The first macro—I named it Non Default Browsers—is just a big "if" statement that sets a variable based on a condition check. Here's how it looks:
The first step sets the nonDefaultBrowser variable to false. The if statement then checks to see if the frontmost app is one of my defined non-default browsers; if it is, it changes the variable's value to true. Otherwise, nothing happens, meaning the value would be false.
If I want to change my list of non-default browsers, I just add or remove them from the list in the if statement.
In Keyboard Maestro, variables are peristent—once they're created, they continue to exist until deleted. When the macro runs, I'll have a variable I can check to see if the frontmost app is one of my non-default browsers, or something else.
The real key to making this work is that Keyboard Maestro lets you execute one macro from another, so all I have to do is run the Non Default Browsers macro before opening a URL.
Then, based on the value in the nonDefaultBrowser variable, I can open the URL in one of two ways. Here's the macro for opening The Robservatory, as an example:
When the nonDefaultBrowser variable is true, that means that I'm in one of the non-default browsers. In that case, the macro sends a ⌘L (which selects the URL bar in Chrome, Firefox, and Safari), pastes the URL, and then sends the Return key.
If nonDefaultBrowser is false, then I'm in Safari or some other app. In that case, the macro uses the Open URL action to open the URL, which sends it to the default browser. (If I happen to be in Safari, it works as expected.)
I duplicate the above macro for each URL I want to access in this manner, and edit the two instances of the URL in each copy. (I could have created a variable that holds the URL for each site, then I'd only have to modify the URL in one spot…but given I rarely change these things, I decided that was more trouble than it was worth.)
I created a group that holds the URL macros, and the Non Default Browsers macro, so I can easily find it in my growing list of macros (and easily disable it if I need to, for some reason):
This setup works amazingly well for me—and the technique of keeping a conditional in one macro, checked by one or more other macros, will probably prove useful in future macros.