Triggering Keyboard Maestro macros remotely

Before version 8, there were a couple ways of triggering Keyboard Maestro macros remotely, but none of them were particularly great.

You could use the Keyboard Maestro web server, either directly or from the Keyboard Maestro Control iOS application (which is very old and outdated, sorry!), but that generally only worked on a local network (unless you have a real NAT-free connection to the Internet or set up port forwarding on your router, both of which are very rare these days).

Or you could make some sort of hack using Dropbox or iCloud Drive and sending a file to your Mac somehow to trigger a macro that way.

But Keyboard Maestro 8 introduces the Remote trigger that lets you trigger a macro from anywhere on the Internet. This allows you to integrate with network services like IFTTT or HealthChecks.io. For example, I use HealthChecks.io to monitor my servers and report if they go down, and it reports by triggering a macro that puts a big red floating window on my screen as well as sending me an iMessage.

The Remote Trigger has essentially two parameters, which are usually two unique IDs (essentially passwords). One can be set to an ID for your Mac (so that if you sync your macros, only one Mac will fire), or it can be set explicitly (in which case it would be synced to your other Macs and all of them would fire). The second one is always explicit.

While you can change the unique IDs that are pre-selected, I would encourage you to leave them as the random IDs that Keyboard Maestro generates unless there is a very good reason to change them. A reason you might change the IDs might be for a trigger you explicitly make public.

Note that these two IDs together are shared by everyone using Keyboard Maestro. So if you make a Remote trigger for “a/b”, don’t be surprised if others end up triggering - keeping the random UUIDs is still a good idea for this reason.

There are a bunch of caveats for the trigger, not least among them are:

  • Anyone who knows the IDs used in the Remote Trigger can trigger the macro - so keep them secure, and limit your use to macros that are relatively safe to run (for example, if someone managed to trigger my HealthChecks.io warning, no real harm would be done).

  • The trigger happens by connecting to a Stairways web server, and by Keyboard Maestro keeping in touch with the Stairways web server. That means that a) any Internet outage between the client, the Stairways web server, and the target Mac might block the trigger; and b) since Keyboard Maestro is not sold as a service, this part of Keyboard Maestro is not guaranteed indefinitely, eventually the server will stop working and so will this trigger.

I look forward to seeing what people do with this new facility.

14 Likes

Hi,

Do i need to keep the web server option enabled to use the remote triggers reliably? I have a 2017 MBP and the remote trigger option isn’t working reliably for me. It does work if the web server option is disabled (but its not reliable). After a few hours it stops working and it will then take a few hours for it to start working again. And once I enable the web server the remote triggers seem to wok reliably. So is enabling the web server a requirement to ensure reliable working of remote triggers? or is it some other issue (because the remote triggers do work intermittently even if the web server is disabled)?

No, remote triggers (ie, triggers using the Remote trigger) have nothing to do with the Keyboard Maestro built in web server.

The remote triggers work by Keyboard Maestro keeping a "long poll" connection to the trigger.keyboardmaestro.com web server. I would guess that some part of the connection between your Mac and the server is timing out the connection and so when the message finally comes through, it can't get from the trigger.keyboardmaestro.com web server to your Mac. If having the Keyboard Maestro web server on makes a difference, then my guess would be that the issue is local to your Mac, so your Mac is deciding not to bother remembering the connection or something like that.

I'm afraid debugging the issue or determining where the problem might lie for your network setup sounds very challenging to me.

Hi,

Thanks for the quick reply. Is there a log that keyboard maestro uses to
keep track of the connection status?

Also you said the app uses a long poll connection and that timeout could be
the reason. So why doesnt the client (my mac) reinitiate the connection
when there is a timeout? I mean it takes hours ours for the trigger to
start working once it stops. So im guessing my mac isnt initiating any
connection during that period (assuming a timeout occured).

Keyboard Maestro will reinitiate the connection if the connection is dropped.

But if there is something in-between that forgets about the connection but doesn't tell the system, the the connection appears alive to Keyboard Maestro, but the trigger message doesn't get through. But really that is just a guess, I have no idea.

There is debugging you can enable to see what is happening with the connection status. Run the Terminal command:

defaults write com.stairways.keyboardmaestro.engine Debug RemoteTriggerMonitor

And then relaunch the Keyboard Maestro Engine (File ➤ Quit Engine, File ➤ Launch Engine).

Then the trigger connection status information will be logged in the Engine.log file (Help ➤ Open Logs Folder).

1 Like

Thank you. I will have a look at the log.

Hi...I can do to make this easier to setup please let me know! Also, do you have examples of the URL that you use for Keyboard Maestro? Screenshots? That would be super helpful to anybody else trying to set this up.

surface mount assembly

I have problems with the remote triggers. After creating a fresh new trigger code it works for some time, then the macro stops firing.
The built-in Assistance tool doesn't recognize the incoming trigger either.
The trigger URL page shows the correct number of the machines that use that trigger.
But the macro still wouldn't fire.
The only solution that I found so far is to restart the KM engine. Then it all works fine for some time again.
Please help what to do. The triggers are awesome. I really don't want to go the Dropbox/file trigger route.
Thank you. I will keep an eye on the updates.
P.S. Version 8.2.4 on Mojave and the V10 on Monterey act the same.

An easy way to verify that the macro is active is to add Status Menu trigger to the macro and verify the macro is being listed in the status menu.

If the macro is active, and the remote trigger is not working, then try disconnecting your network (unplug your ethernet cable to your Mac, or turn off your wifi), then reconnect it. See if that resolved the issue.

The remote trigger works by having a long lived connection between Keyboard Maestro Engine and the remote trigger server. Such long lived connections require that the network between the Mac and the server must remember that connection is alive and if any part of that connection fails to remember it then that can cause the problem. Generally that only happens at the local end with some networks.

You can add debugging for the Remote Trigger system using the command:

defaults write com.stairways.keyboardmaestro.engine Debug "RemoteTriggerMonitor"

or even more:

defaults write com.stairways.keyboardmaestro.engine Debug "RemoteTriggerMonitor RemoteTrigger"

And then monitor the Engine.log file to see what is happening.

1 Like

Thank you for your reply.
I think the problem is not in my network.
KM wouldn't respond for about 30 min, not even reacting or logging neither shared nor local remote triggers.
Then after about 30 min of being offline it fixes itself, works for 5 min and then goes dead again. Then the process repeats.

Here is what happens in the log while KM remote trigger monitor recovers itself after being down for 30 min:

2022-05-21 07:38:24 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 07:38:24 RemoteTriggerMonitor reopen
2022-05-21 07:38:24 RemoteTriggerMonitor open
2022-05-21 07:38:24 RemoteTriggerMonitor actualOpen
2022-05-21 07:38:25 RemoteTriggerMonitor did open
2022-05-21 07:38:25 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 07:38:25 RemoteTriggerMonitor send REG:{###}
2022-05-21 07:38:25 RemoteTriggerMonitor got message: GOOD

The remote trigger worked a few times just a minute ago, but now KM has no connection again, it is waiting for the "communication satellite to show up on the horizon" I guess :slight_smile:

more:

2022-05-21 08:12:22 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 08:12:22 RemoteTriggerMonitor reopen
2022-05-21 08:12:22 RemoteTriggerMonitor open
2022-05-21 08:12:22 RemoteTriggerMonitor actualOpen
2022-05-21 08:12:22 RemoteTriggerMonitor did open
2022-05-21 08:12:22 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 08:12:22 RemoteTriggerMonitor send REG:{###}
2022-05-21 08:12:22 RemoteTriggerMonitor got message: GOOD
2022-05-21 08:49:14 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 08:49:14 RemoteTriggerMonitor reopen
2022-05-21 08:49:14 RemoteTriggerMonitor open
2022-05-21 08:49:14 RemoteTriggerMonitor actualOpen
2022-05-21 08:49:15 RemoteTriggerMonitor did open
2022-05-21 08:49:15 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 08:49:15 RemoteTriggerMonitor send REG:{###}
2022-05-21 08:49:15 RemoteTriggerMonitor got message: GOOD
2022-05-21 09:22:12 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 09:22:12 RemoteTriggerMonitor reopen
2022-05-21 09:22:12 RemoteTriggerMonitor open
2022-05-21 09:22:12 RemoteTriggerMonitor actualOpen
2022-05-21 09:22:12 RemoteTriggerMonitor did open
2022-05-21 09:22:12 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 09:22:12 RemoteTriggerMonitor send REG:{###}
2022-05-21 09:22:12 RemoteTriggerMonitor got message: GOOD
2022-05-21 09:56:02 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 09:56:02 RemoteTriggerMonitor reopen
2022-05-21 09:56:02 RemoteTriggerMonitor open
2022-05-21 09:56:02 RemoteTriggerMonitor actualOpen
2022-05-21 09:56:02 RemoteTriggerMonitor did open
2022-05-21 09:56:02 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 09:56:02 RemoteTriggerMonitor send REG:{###}
2022-05-21 09:56:02 RemoteTriggerMonitor got message: GOOD
2022-05-21 09:59:36 Execute macro “Cancel All Macros” from trigger The Hot Key Escape is pressed
2022-05-21 10:28:38 RemoteTriggerMonitor didCloseWithCode 1001 reason Stream end encountered wasClean 0
2022-05-21 10:28:38 RemoteTriggerMonitor reopen
2022-05-21 10:28:38 RemoteTriggerMonitor open
2022-05-21 10:28:38 RemoteTriggerMonitor actualOpen
2022-05-21 10:28:39 RemoteTriggerMonitor did open
2022-05-21 10:28:39 RemoteTriggerMonitor send IAM:1:8.2.4:{###}:OK
2022-05-21 10:28:39 RemoteTriggerMonitor send REG:{###}
2022-05-21 10:28:39 RemoteTriggerMonitor got message: GOOD
2

This is behaving exactly as I'd expect if some part of the network is quietly forgetting about the open connection.

The connection should not be failing, it is marked as TCP “keep open” stream. So some part of the network connection is failing to keep the connection information alive.

Every 30-60 minutes Keyboard Maestro sends an active ping to test the network and every time that is detecting that the connection has failed.

Thus the connection will be working for a short time after the connection is reopened, and probably that time will be extended if there was and remote trigger event that caused more data to flow. After that, the network system is failing and silently dropping the connection route. And Keyboard Maestro is detecting that at the next active check.

Unfortunately, this is caused by network hardware, probably in your house, potentially in your ISP, failing to keep the connection information.

Short of replacing your local hardware (and hoping that works) or forcing a remote trigger alternating active and inactive every minute or so, I don't know of anything else that can be done.

I am having this same issue and wonder if a resolution was found?

There isn't really any resolution possible with network gear that ignores the keep-open flag.

What you can try is configuring a macro that does nothing and has a remote trigger, and that you have a global macro configured to toggle the enable of the macro on and off every 5 minutes (on for five minutes, off for five minutes).

That will force data down the connection every five minutes. Maybe that would be enough to make it work.

Do not do it any faster than every five minutes or you risk being blocked by the server for overuse.

Will do. Many thanks for the speedy reply!

1 Like

If anybody else is having this issue, I eventually found a work around. I signed up to Nord and use a VPN on the receiving computer. Cost a few bucks but no more problems.

1 Like

That likely indicates the router causing the problem is near you, either in your house or your ISP. But it's just a guess.