Might be a stupid idea, but I didn't find an easy way to temporarily disable or pause the KM engine.
I have some macros that automate things with global triggers, e.g. map shares when connect to specific networks or disable WiFi when a thunderbolt network interface connects. In certain circumstances, it would make sense to temporary disable those. Yes, I could just disable the macro group where they are in, but they might be scattered across different ones or one could be not aware of all of them. So it could be helpful to just globally disable everything and then enable it again.
Just to clarify: I already have a working solution, but I feel this could be helpful as a general out-of-the-box KM feature (KM action and an option for the menu bar icon maybe).
Obviously, the KM Engine has to be running in order to execute any macro. So we can’t use a KM macro to start the KM Engine.
I’m pretty sure a script could be written to stop the Keyboard Maestro Engine process, and then another script to start it, but I’m not sure how off the top of my head.
Stopping the engine seems entirely feasible through a macro; the real issue, as you say, is starting it again. Fortunately, the solution is very easy; on a standard install where KM is located in the root Applications folder, this simple shell script will work:
open "/Applications/Keyboard Maestro.app/Contents/MacOS/Keyboard Maestro Engine.app"
It’s easy to store as a snippet in an app like Typinator and run it from Terminal or a launcher like LaunchBar or Alfred, or even to make a custom action/workflow for the latter two options. I did just that for Alfred, and showed how to do so here.
Yeah, you guys are totally right. Didn’t even think of that
As I said, I have a solution: All those macros are in one macro group and I just disable that group. Works for me, but I feel like it should be a KM standard feature to pause the engine through the menu bar item.
The macro would work if the activate/deactivate macro group had a “all groups except this one” option or if could activate/deactivate smart groups.
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/04/20 09:54
# dMod: 2018/04/20 09:55
# Appl: Keyboard Maestro Engine
# Task: Quit and restart the Keyboard Maestro Engine
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Quit, @Restart, @Keyboard_Maestro_Engine, @Engine
----------------------------------------------------------------
tell application id "com.stairways.keyboardmaestro.engine"
if running then
quit
else
launch
end if
end tell
----------------------------------------------------------------
This sort of thing is a good reason to have FastScripts on your system – even the free version which has unlimited menu scripts and 10 available keyboard shortcuts. (For $9.95 U.S. you get unlimited global and app-specific keyboard shortcuts.)
I currently have 25 AppleScripts that drive the Keyboard Maestro Editor in various ways, and they're all in FastScripts – because I don't want Keyboard Maestro driving itself – particularly since its dead in the water when the engine isn't running.
I need a number of my scripts to work when the KM Engine is not running,
There are many other advantages.
Testing AppleScripts using a different run mechanism.
Offloading long-running processes that reduce performance of the other app.
More I can't think of pour le moment.
I'm still using it alongside Keyboard Maestro 15 years after I bought it, because there's synergy having both – and that lets me get more work done.
I feel the same way about Typinator. Although Keyboard Maestro will do most of what Typinator will do (albeit a little more awkwardly), Keyboard Maestro can't do text-expansions in its own running UI Actions – Typinator can – and vice versa.
Once again there's good synergy between the two utilities.
Thanks, Chris. I had a feeling you would have a great script for this.
To All:
Here's a minor mod of Chris' script to give you a notification so you know for sure which action has been taken:
tell application id "com.stairways.keyboardmaestro.engine"
if running then
quit
set msgStr to "STOPPED."
else
launch
set msgStr to "STARTED."
end if
end tell
set msgTitleStr to "Toggle KM Engine On/Off"
set msgStr to "KM Engine has been " & msgStr
display notification msgStr with title msgTitleStr sound name "Tink.aiff"
Although for me the Status Menu stands out enough it's not necessary.
I also use the “Iconaholic Loud” icon style:
Because it makes VERY sure I know when macros are running.
It saved my bacon once when I noticed a macro was running longer than it should – a shell script macro, which I promptly killed – using my global Kill-All-Macros keyboard shortcut.
⌘⌥⌃⇧K
That saved me from scragging my whole downloads folder.
Another good reason for doing this is to temporarily quit the KM engine in order to enter a special character (like u-umlaut, for example) by using a key combination (like option-u in the case of umlaut) that might otherwise be assigned to a KM macro.
In my case, that’s even more work (and more to remember) than occasionally pausing the engine. If I were typing umlauts and the like on a daily basis, it might be different. My point is that whenever a key combination is needed for something (whether for text or anything else), but it’s unavailable because of using it as a trigger in KM, it’s nice to be able to pause the engine.
I was just about to ask about this when this was helpfully listed as "similar to" my post. And I have the same reason—I have a (inherited) macro assigned to Opt+3 because being in the colonies I never need a pound sign. Until I needed a pound sign today.
So, another vote for a menu item to pause (not quit) the KM engine, preferably a toggle, so we could use the same (Mac, not KM) hotkey to turn it on or off. (Even if KM didn't assign a hotkey, we could assign one to the menu item via the Mac Keyboard Shortcuts.)
Where are you thinking of a menu item? Do you mean something like a Pause Engine menu item in Keyboard Maestro Editor? If that, you could use Keyboard Maestro (or System Preferences) to assign a shortcut to File > Quit Engine and also add a shortcut in System Preferences for File > Launch Engine (the same shortcut will work assigned to both). Even so, the KM Editor would need to be frontmost, so that makes me uncertain I'm understanding.
Or a menu item somewhere else?
If you don't want to make it so the KM Editor needs to be open, you could do it with a KM macro that executes an AppleScript, activated with a hot key or other KM trigger. This script will quit the KM engine then relaunch it after a preset delay (in the script, change the delay to whatever number of seconds you'd like from the number shown of 30 seconds):
tell application "Keyboard Maestro Engine"
quit
delay 30
tell application "Keyboard Maestro Engine"
activate
end tell
end tell