I am trying to create a web url-based macro. I mean "a macro that I would trigger via a keyword and would be triggered only on a specific website".
For example: when on the Keyboard Maestro forum and only on the Keyboard Maestro forum, typing "nn", would trigger some action.
For this to work, I need to get the url of the browser I am using to make sure I am on the Keyboard Maestro forum website.
I honestly do not know how to make it work. I took a look at this thread ( [How to use Chrome URL as a macro trigger?]), but as I am using the Brave browser 90% if not more of the time, that didn't really help.
What strikes me the most is I can't set the right conditions so Keyboard Maestro triggers the action I want to trigger.
I have a macro that I only set to trigger when I'm on the Keyboard Maestro forum website. It works really well using the method you stumbled upon above but prematurely gave up on. Whilst Keyboard Maestro doesn't, as far as I am aware, have a URL-based trigger, the webpage title is often just as good.
It did necessitate creating a specialised macro group just to house a single macro for one single website. Here it is:
Creating a macro group specific to a particular webpage based on the browser's window title
Ignore the name of the macro group, which does allude to using the URL as a discriminator, but it doesn't. It simply ensures the macro is only available in the web browsers I use when the active window's title contains "Keyboard Maestro Discourse".
As I'm typing this reply, I'm in Google Chrome and the title of the window is: "Best way to use a browser url as a macro trigger? - Questions & Suggestions - Keyboard Maestro Discourse", which hopefully makes sense how and why this method works, providing that, no matter where I navigate to on this forum, the words "Keyboard Maestro Discourse" remain a part of the window title, even if the rest of it changes.
Another way of achieving something similar that almost mimics a URL-trigger is to have a macro available on a per-application basis (Brave in your instance), but make the first action an assertion that cancels the macro upon failure, such as when the URL of the front browser doesn't contain "forum.keyboardmaestro.com":
Using an assertion to test the URL in an application-specific macro
I'm not certain whether the %FrontBrowserURL% token will work with Brave, but there will probably be other ways of getting the URL if not. The limitation of this method is that any hotkey I assign to trigger it will be unavailable for general use any time you are using your browser, regardless of what site you are on. That is, a true URL-based trigger would overwrite the functionality of the hotkey just during the instances when you are visiting that website, but restore its original function when you navigate away from it; here, if I decide that I want to use the ⟨tab⟩ key (which is what I set as my hotkey for my Keyboard Maestro Forum macro above), if I implemented it using this method, I wouldn't have access to the ⟨tab⟩ key at any other time.
Instead of canceling on failure, you can have the conditional type the key you've given up as the trigger. That way, you don't have to give it up. The key will work the way you want it to in either condition.
I believe Peter has stated a few times before that simulating a key combination that is a designated hotkey is unpredictable and generally advises against doing this as one could end up in an infinite loop of self-spawning child instances of your macro.
The reason I've never been worried about that is that it seems fundamentally different to have a "type command T" action in a macro triggered by command-T, compared to having an "activate macro x" action within macro x.
That latter would be a loop nightmare, because the macro calls itself, whereas the former just passes a keystroke. By the bye, as a quick test, I just created a macro that simulates "option-Q", which is what I use as a trigger to bring up the KM editor (via a different macro). When I invoke the macro, it does not have the effect of invoking the other macro. Instead, it just types "option-Q".
Yeah, I've done the same experiment in the past as well. Often, when someone tells me not to do something, I will give it a try anyway. But I'm still not going to set up my macros to work like that, even though I know you can just press Cancel All Macros from the menu bar.
I use an extremely inelegant method to do something similar...I invoke a Cmd-L to select the URL in the address bar, then Cmd-C to copy it to the clipboard, the use Switch/Case to see if the clipboard contains part of the URL I'm looking for. You could also you If/Then/Else.
I am trying to implement url as trigger and end up here.
I create a new macro group as below:
It works most of time but not reliably all the time. Sometimes when I switched away from a tab from this forum to another tab that doesn't contain this word, it also triggered, then switch back to this forum but it doesn't trigger.
Is this still best way to use chrome title or url as trigger?