Trigger Macro By Script


#1

Hello,

I see that there is a possibility to trigger a macro by script.

Is it possible to built a script with multiple conditions for trigerring a macro like:

If Safari browser is running and its front tab contains URL then trigger macro periodically every 5 seconds if not then do nothing.

Looking forward to see an example on such script.

Thanks in advance.


#2

Hi Kirill,

I could be wrong, but I think a macro would be better for this use-case than a script. I would use a focused window trigger with a macro in a Safari-only macro group, use an If/Then action to make sure that the URL is the one you want before proceeding, then put the macro in question in a loop that keeps it running while the %SafariURL% token contains the URL in question:

image


#3

Hey Gabe,

I am doing it exactly the same way as shown above + periodic macro trigger every 5 secs, i though that it may be possible to trigger the macro by script (as triggering macro to often gets the CPU hot) but now i think it is not a good idea, anyway thanks for your interest!


#4

Perhaps the best way to implement that is to create a Macro Group for Safari, so that its Macros are active ONLY when Safari is FrontMost (or you could use Running), AND the frontmost window/tab contains some text, like "Keyboard Maestro". Unfortunately there is not a condition for URL, only Window Title.

image

Now you can use a Macro with a Periodic trigger

While you can set this to seconds, I would encourage you to make the period as large as possible, as a highly frequent period will require a lot of CPU.

Does this make sense?
Questions?


#5

Hey @JMichaelTX, tried this scenario as well, it only works when the window is frontmost, it would be very nice if one more option for macro groups will be added in newer versions of KM - "Available when a window title contains" excluding focused - so it work in both states if the window is at the front or is not at the front.

Adding URL condition would be also very useful.


#6

Hey Kirill,

That's unlikely to ever happen, because Keyboard Maestro would have to constantly scan all window titles – instead of what it does now – which is to pay attention to front window change events as reported by a publicly available API.

Same as above.

-Chris