Tag: KeyboardMaestro

A challenged I’ve always faced in running Keyboard Maestro on multiple Macs, is the maintenance of macros that are common to all, i.e. when updating a macro on one machine (say, changing the API keys of a service I’m accessing), I have to remember to go make the same updates on the others.

Keyboard Maestro provides a solution to this problem, by allowing you to synchronize your macros across multiple machines. Their implementation, however, and in contrast to say, Hazel’s folder-scoped implementation, is all or nothing—meaning that you can’t have macros on one machine that don’t exist on the others. And that can become a problem, especially with macros that are scheduled to run periodically.

Keyboard Maestro provides two approaches to address this problem:

The first is the ability to, for any given group (folder) of macros, to click, “Disable on this Mac”.

Unfortunately, there’s a number of shortcomings to this option. For example, anytime you add a new group of macros to a given machine, you have to remember to potentially go around disabling them on the others.

The second approach, and better in my opinion, is to condition the execution of any macro on the UUID (universally unique ID) of the machine on which the macro is running. Here’s an example of how this works.

The first step is to maintain a macro that determines the UUID of the current machine, and defines a list of named UUIDs for machines you’ll later be referencing. I run the following macro daily, and whenever I add a new machine, I’ll add its UUID to the list of named machines by temporarily running the disabled action that copies the current machine’s UUID to the clipboard.

With this in place, I can now condition the execution of other macros by machine. The following is an example of a macro that runs daily, and quits FaceTime on my MacBook Pro.

If I wanted this macro to run on two machines, I could add a second UUID check, and change the condition to “any”.

While this approach requires additional effort in creating your macros, it provides big benefits in being able to manage from a single machine, the conditioned execution of macros on all of your machines.

Rebooting the router

The router frequently hangs—about once every few days—and requires a reboot. Manually logging into the web interface to click the “reboot” button gets tiresome, and so I decided to see whether I could automate this with Keyboard Maestro.

I have KM running on a Mac mini whose ethernet interface is connected to my VPN-protected LAN, and whose wifi interface is connected to my ISP’s router. The wifi interface is configured as default in the Network Settings preferences such that all internet traffic is, by default, routed through the ISP’s router. (This is to provide Slink-based remote access to my home network.)

So the first problem to solve was how to test internet access on the non-default ethernet interface? Fortunately, the gracious KM author, Peter Lewis, discovered that the ‘ping’ command supports an option (‘-b’) to specify the network interface.

Now that I could check if the router was down, the next problem to solve was programmatically rebooting it. The Tomato software, being a Linux distribution, supports SSH access, and Peter pointed out that if I install my SSH keys on the mini, KM could then login to the router without a password. That, and a little Googling, allowed me to figure out the KM text script needed to reboot the router via SSH.

Putting this all together, here’s the KM macro (configured to run every 5 minutes) I created to test if the Tomato router is down, and reboot it if so. (It’s configured to run every 5 minutes.)

Now, you might be wondering what the ROUTER_REBOOTING variable is for. Turns out, there’s another Tomato-related issue I also solved with Keyboard Maestro.

Restarting the router’s VPN client

The Tomato router supports two VPN clients, VPNClient1 and VPNClient2. I have client 2 connected to a US-based VPN server, and route my AppleTV through that, allowing me to watch content that is IP-restricted to the USA. For minimum latency, though, I have client 1 connected to a server in France, and have it configured to route all other traffic on my home network.

Problem is, when the router boots, and perhaps due to the order in which the two clients start, all traffic ends up getting routed through US-based client 2. To fix this, I just need to stop and restart client 1.

To address this problem, I created another KM macro that that checks the geo-location of my external IP address, and if it’s not “FR”—and if the router isn’t currently rebooting; hence the ROUTER_REBOOTING check—then it restarts the VPN client 1.

In a recent blog post I explained how I secure my home network with a VPN. In that article, I also explained how I enabled external access to my home network, using the Slink software running on a Mac mini server, whose primary network interface is wifi connected to my ISP router, and second network interface is ethernet connected to my home gigabit switch.

This setup works great, but it did require solving a tricky problem:

My home wifi network (created by the AirPort Extreme) is called “Hacienda”, and the wifi network created by the ISP router is called “HaciendaOlive”. Since I want all my home devices connected to Hacienda, that network is given first priority over all other known networks on my iPhones, iPads, etc.

The problem is that that network priority list propagates to the Mac mini (and all my devices) via iCloud, and so anytime there’s a network interruption or the machine reboots, the Mac mini connects to the Hacienda wifi network (instead of HaciendaOlive)—which of course kills my external access to that machine.

What I need is that the mini, and only the mini, has HaciendaOlive set as its highest priority wifi network. But this doesn’t see to be possible, unless I’d be willing to disable iCloud on that machine.

My solution to this problem was a Keyboard Maestro macro which runs every five minutes, checking whether the computer is connected to the HaciendaOlive network, and if not, switching it to that network. This required researching some obscure AppleScript code, and so I thought I’d post the macro here for the benefit of others searching for how to switch wifi networks using Keyboard Maestro. The blurred text in the image, is the wifi network password.

Step 3 required copying and pasting both the URL and the article title, separated by an em-dash, into the twitter client. I simplified this with the following Keyboard Maestro macro, which, in addition to forming the correct tweet text, also strips out the blog name from the title—for each of my two blogs Dafacto and Rantbox.

This morning I was trying to create a Keyboard Maestro macro to automatically send an email to my team members on the last day of each month. I got stymied when I realized the the time schedule trigger is basically limited to “Daily at a certain time”. Continue reading Arbitrary scheduling in Keyboard Maestro

While waiting for version 4 to be released, I’ve had to temporarily uninstall the MailTags plug-in from Mail.app in OS X Mavericks. One of the most-used features of MailTags for me was its ability to copy the selected message’s URL to the clipboard.

A “message URL”? That’s correct. Mail supports URLs to individual messages, that when accessed open the particular message in Mail.app. This is what one looks like:

I often use message URLs to provide myself with reference to conversations, important decisions or tasks that are captured in emails.

Without MailTags installed, though, I’ve been really missing this feature. My friend, Stefan Seiz (@seiz), however, was kind enough to email me an AppleScript that provides this same functionality. From that, I created a Keyboard Maestro macro, and assigned it to a keystroke.