I love KM. But I do have to stop and/or start the engine (up to) dozens of times per day, so I started to wonder if there was an easier way to do it. Right now I stop the engine by clicking on the KM Engine menu in the menu bar, and then if I want to start the engine I have to launch KM Editor (or, if it's already running, switch to it) then I have to click on its "File/Launch Engine" menu item. That's a lot of steps.
In theory the KM Engine can be used to stop itself, but it (obviously) can't start itself. So I was wondering what part of macOS can be used to do both of those things. naturally, the macOS app called Shortcuts was probably the solution. After 15 minutes, I had a simple shortcut running that does what I want.
I actually have two shortcuts... one that reboots the Engine, and one that toggles it. For today, I'll simply post the one that reboots the engine. Here is a screenshot of the shortcut, which you can use to create your own "shortcut."
The "sleep 1" command in the above action seems to prevent a timing issue that occasionally resulted in a shell script error message.
Notice the checkbox for "Pin in Menu Bar". This allows you to access this macro from the Shortcuts icon in the Menu bar, which is a convenient way to trigger this macro.
To make it even easier to use, drag the Shortcuts icon in the Menu Bar next to the KM Engine in the Menu Bar (to do that, use COMMAND-LeftMouseClick to drag the icons to different places in the Menu Bar.)
It seems that macOS has a limit of triggering the same shortcut once every six seconds. So if you try to trigger this shortcut twice in a row, you will have to wait at least 5 seconds for a message to disappear before the menu reappears to let you run it again. That's not a problem, since nobody will need to reboot the engine twice in 6 seconds.
Even better, the Shortcuts app allows you to assign a single key to this shortcut. So for example, I can assign the key "Command-Home" to the shortcut, and now pressing that key will reboot the Engine.
Just click on the button "Add Shortcut Key" and press Command-Home. Then it looks like this:
Now I can reboot the KM Engine with a single key. Yay!
(Note: Bear in mind that the Shortcuts app's shortcut keys seem to have a lower priority than the active app's shortcut keys, so if the app you are using already uses the key you assigned to the Shortcut, your app's definition will take precedence. So use a shortcut key that your apps don't use. Command-Home is probably not the best shortcut to choose, since many apps have this key pre-defined. I still don't understand this topic fully.)
In fact, you can even have the KM Engine send a key to macOS to call this Shortcut, but that's an unnecessary level of redirection, so I won't explain it here (even though it works, and it's cool to realize that using this method the KM Engine can restart itself.)
If people want to see my separate Shortcut which toggles the engine rather than restarts it, I can post that also, probably as a reply within this thread.
P.S. I used a "robot head" as my icon for my shortcut. To me that seems to capture the essence of what KM is. There are hundreds of icons to choose from, but I couldn't see anything better. Therefore, I recommend that anyone who creates Shortcuts that pertain to Keyboard Maestro should use the robot head icon.