Some site I was browsing through had posted a review of a $4 app that reported whether or not you were connected to the internet. And while I'm sure the app has some useful features, that seemed like the kind of task that Keyboard Maestro could handle with ease.
After a bit of testing to find a simple way to check the internet connection, I wrote a very basic four-action macro that does just that, and only that: It tests your internet connection once a minute. If everything's good, you'll see a ✓ in the menu bar. If it's not good, you'll see a big red X, like this: .
Download Macro(s): Check online status.kmmacros (5.8 KB)
Macro notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System information
- macOS 14.7
- Keyboard Maestro v11.0.3
You can change how often it runs, of course, but it's a very fast, minimal overhead macro—it's got a timeout set to two seconds on the action that checks the connection, so that's the longest it will ever be running (well, very slightly longer to process the next two actions).
How does it work? It simply tries to ping
a host that should be up 99.999% of the time—the public DNS that Cloudflare provides at 1.1.1.1. The specific command is this:
ping -c 2 -o 1.1.1.1
That will ping the address twice, and exit on the first successful ping. If it's not successful, the action will time out after two seconds (because the ping won't be completed in that time).
The macro then just checks the ActionResult
token. If it's not OK
, that means the ping failed, and the connection is probably dead. As such, it then loads the into the variable that the macro group displays in the menu bar.
If it is OK
, then all is good, and the ✓ is loaded into the variable.
Keyboard Maestro's ability to use a variable as the item to show in the menu bar for the macro group is incredibly useful here, allowing easy communication of the state of the internet connection by simply changing a variable. Very cool.
Anyway, some might find this useful, if nothing else as a basic building block to use in a more-advanced version of the macro—this one cares nothing about how you connect, doesn't try to check the health of Wi-Fi and Ethernet separately, etc. It just uses whatever connection is active to see if it can reach the net.
-rob.