Help with kmtrigger and URL scheme (open a link in a specific app)

,

Hi folks,

I'm dipping my toe in KM and have come across something which my be simple for experts here, so I need a helping hand.

With the help of apps like Unity and Coherence, I have 'nativefied' a few apps, among which Reddit to contain all my browsing session on this site, keep me logged in and avoid jamming my main browser with multiple tabs. So Reddit appears as a standalone app.

I am now trying to write a KM macro to open that app when I click on a Reddit link anywhere, let's say in Telegram. After wandering for a few days, I have narrowed down my search to kmtrigger and URL schemes.

My point is : what is the exact syntax of such a macro?

Thank you in advance.

PS: Resources explored so far:

I'm not 100% sure I understand you're question.. but if you're trying to 'send' a URL to a specific app, you can use a shell script:

open -a <specific app> <url>

Thanks for replying.
I'm yet to dig deep, but how to take into account the whole scheme (reddit.com/r/ or reddit.com/u/) and not only a specific URL?

I don't believe Keyboard Maestro has a trigger of this nature. It can't detect when you click on a link that happens to be a URL.

No, this won't detect when you click on a link in, for example, Telegram, or any link for that matter. kmtrigger: is, as you stated, a URL scheme that is registered with the system to associate itself with a specific application—in this case, Keyboard Maestro (Engine).

Indeed, that is the tricky part. You either need something that can intercept your hyperlink clicks; or you need to introduce an interim step where you actively send the URL to a program/workflow/macro/script to be processed appropriately.

For the second method, you could consider creating a systemwide service with Automator, which you would have to right-click and specifically select that service whenever you want to have a Reddit link sent to your application. This has the benefit of being easy to set up, but has the drawback of being a somewhat unsatisfatory method.

With regards to the first method, I imagine you would need an application to register itself with the system as being the default handler for URLs, so that whenever a URL is clicked, it gets sent to this default application, which then decides what to do with it. The application can be a simple AppleScript app you create yourself; the important bit is editing its info.plist file to include the list of URL schemes it will register itself as being able to handle, i.e. http: in this case. Then the AppleScript would either send the URL to your Reddit app, or forward it onto Safari or Chrome or whatever. This has the benefit of achieving what you want, but the drawback is it's quite a technical thing to set up.

But...

Third-party solution

If, however, you don't mind going with a different third-party solution, then an open-source app online called BroswerDispatcher sounds like it does exactly that which I just described, but with a very slick, customisable interface:

https://electronjs.org/apps/browser-dispatcher

I haven't used this app before (I literally just found it), and it hasn't been updated in about a year. But, chances are is that it will still work fine and do exactly what you want.

Many thanks for the third party solution!

In fact, I've trying to achieve this for a while, RCDefault doesn't seem to be able to do it and someone pointed me to KM.

Will try this asap :+1:t2:

This isn't going to do the job you want, but may help you explore another avenue.

I created an Open in Chrome macro, which I use for certain links (I have a preference for Safari, but I handle all Google-related links separately in Chrome.)

When the mouse is left hovering over a link, the hot key ^G will copy and open that link in Chrome. Finder is treated as an exception, and allows Google documents to be opened in Chrome.

Open in Chrome.kmmacros (22.7 KB)

We had a bit of a discussion about this approach here, which may also give you some ideas?

Choosy is an app that allows you to specify Site Specific Browsers as the default for specified URL's, and it has a long free trial so you can see if it works in your case.

$10.00 U.S.