It's a bit complicated, but the logic is simple. I'll try to describe how I did it.
Create Two Macros
-
Create one macro in KM.
-
KM macro: If %TriggerValue% is "AppleScript", then disable the macro group. Else,
- if the macro group disable, enable a macro group (or a set of macros) and then call BTT to bring up the floating HTML window (the small sign to show that the macro group is enabled). Eles,
- disable the macro group.
- if the macro group disable, enable a macro group (or a set of macros) and then call BTT to bring up the floating HTML window (the small sign to show that the macro group is enabled). Eles,
-
KM macro: If %TriggerValue% is "AppleScript", then disable the macro group. Else,
-
Create one named trigger (equivalent to KM macro) in BTT.
-
BTT Named action: to bring up the floating HTML window. This is just a very small icon (screenshot below). At click, it (1) triggers the KM macro to deactivate the macro group via AppleScript (with parameter "AppleScript") using JavaScript in the floating HTML window and then (2) closes itself.
-
BTT Named action: to bring up the floating HTML window. This is just a very small icon (screenshot below). At click, it (1) triggers the KM macro to deactivate the macro group via AppleScript (with parameter "AppleScript") using JavaScript in the floating HTML window and then (2) closes itself.
Workflow:
- use hotkey to trigger the KM macro.
- Result: the macro group is enabled, and the BTT named action is triggered, displaying a sign (can be anything we design).
- BTW, BetterTouchTool allows the HTML background to be transparent. Therefore, you only see an icon above, no window title bar etc. Shout out to @avialan who has just made a feature request for Translucent Custom HTML Prompt for KM.
- If I want to disable the macro, just click this sign. It will call Keyboard Maestro to trigger KM2. Then it closes itself. The cycle is complete.
Floating HTML in BTT
The key is the floating HTML prompt in BTT. Thankfully, BTT has already provided an excellent example here (See especially the example: "Transparent webview that displays a fancy action menu"):
https://docs.folivora.ai/docs/10_0_floating_html_menu.html
Edit: Made some improvement. only one macro needed for KM and BTT respectively.