Can KM Intercept Specific Clicked URLs and Redirect Them to a Non-Default Browser?

Is Keyboard Maestro capable of doing the following?

If I click on a link with a specific domain (e.g., youtube.com*) in an email or from Twitter, I want to have those youtube links open in a non-default browser, such as Firefox, instead of going to Safari as they normally would.

My default browser is Safari, but a handful of websites either render better or properly in Firefox or Chrome than they do in Safari. So, I want almost all clicked links to open in Safari, but I would like a few urls to open in Firefox when clicked in another app (e.g., Twitter, Mail, etc).

Is this possible with KM?

Hey @Buttonhole,

Welcome to the forum!   :smile:

In a word – nyet.

You can change the default browser temporarily and then change it back, although that's not a Keyboard Maestro function – you have to script it.

https://forum.keyboardmaestro.com/search?q=change%20default%20browser&expanded=true

On the other hand – if you have the full text link it's possible to do with native Keyboard Maestro actions.

This critter might be worth a look as well:

https://www.choosyosx.com/

-Chris

1 Like

Thanks so much for the Choosy recommendation. I've never heard of this app before but it does exactly what I wanted. Much appreciated.

1 Like

Do you have thoughts on how this compares to Finicky?

BetterTouchTool also supports this.
But it is not as easy to setup as more dedicated apps for this. But if BTT is in your arsenal, then it can do this.

2 Likes

I have just looked at Finicky and have replaced it instead of BTT. It has the feature to open specific sites with specific profiles in Chrome, which I could use.

Good find. Looks like a good, free alternative to Choosy.

can you speak to if this might be a new feature in an upcoming release?

i love and have been using Choosy for several years now, but i've found a need to occasionally rewrite links that i click, which Choosy can't do. it looks like Finicky could. however, i'd rather just do this with the tools that i already have and know.

Hey Bryan,

You'd have to ask @peternlewis about that to know for certain.

But as far as I know Apple doesn't have a public API for doing this, and unless/until that happens Keyboard Maestro will never have the feature.

Peter only uses public APIs and never hacks the macOS to add features, so Keyboard Maestro is not prone to breaking when Apple changes things behind the scenes.

-Chris

1 Like

Some mice come with software that let you redefine the primary mouse click button and send a USB code instead, which I think KM can then trigger on. I've done that a few years ago and it worked for me then. In this case, if the user did that, he could intercept the mouse click and then take action or simply pass the click through to the app with no other action.

So if this user is willing to do that, he might be able to make his idea work.

Or maybe I misunderstand what the user wants.

i don’t think doing this requires any hacks. i could be wrong, but i’m pretty sure that “all” these apps (like Choosy) do is register as a browser, intake the URL macOS sends them when a link is clicked, and then send the URL on to the browser that matches the rule.

KM would have to be set as the default browser and ingest the URL, then let us make a macro that is triggered on an ingested URL and makes them actionable.

another use case to try and push this feature request- say you click on a zoom link to join a meeting, KM will be triggered, you can then match zoom links and have KM do whatever to setup for your meeting while also directly opening the zoom link in the zoom app instead of default browser -> zoom (leaving a dumb tab behind). this could be pretty powerful.

You would have to set Keyboard Maestro as your default web browser, and then specify in it how to process the URLs.

It's possible, but not really a feature I've considered. You really want a tool that has this as a particular feature, and it does not really integrate all that well with Keyboard Maestro’s other features. I suppose you could do the mappings as macros with a URL trigger, but it'd be quite cumbersome to do what you normally want to do.

Nobody seems interested in my solution (indeed, this thread has already been marked as Solved) but I'm going to post my code here anyway because I hate to create a solution and then let it go to waste. Feel free to ignore this solution.

This code could be made more robust but right now it works and it's here for explanation purposes only. It works only when you have a mouse that can have its primary button assigned to a USB code. Not all mice permit this. If you have such a mouse, redefine the primary mouse key to a USB device code, then create a macro as follows which triggers on that code.

image

This code opens links with the string "youtube" in Safari but opens links without "youtube" in some other browser. The final action activates Chrome, but since I don't have Chrome (or Firefox), and don't want it, the final action was disabled in my macro above.

Maybe I misunderstood the original question, but this seems to be a solution to that question, as long as your brand of mouse supports primary button redefinition.

exactly this. in it's most basic form a macro with:

  • Trigger - URL received
  • Action - Open URL URL with Application.

a more advanced one could couple that with an if block. If The variable contains substring; Search and Replace; Open URL.

i agree that it could become cumbersome quickly if built out all within one macro.

one way to make it a little less cumbersome could be to make one macro that matches URLs, which then calls other macros to handle that URL:

  • URL Received
  • Set the URL to a variable
  • If block to match a substring of the URL
  • On match, call a specific macro
  • Specific macro handles what to do with the URL: manipulate it, open other programs, close programs, open it in a specific browser, open it and have KM click around the site or fill out a form, run a Bunch, etc.

hopefully that last point shows that this could integrate well with other features of KM.

(side-note, thanks for all of your work on KM, it's awesome.)

1 Like

It is possible, but I have no current plans to implement this currently.

Maybe one day.

1 Like