A new technique to toggle Stream Deck buttons using KM

Now that I have a new M3 iMac, I wanted to use my iPad again with the "Stream Deck Mobile" software available for iPadOS. (I think there's a free version, but I'm paying $3/month for the full version.) I could have used my solution for my M1 Mac, but I wanted to take this opportunity to rethink my approach to make it better, and I found an unusual new technique using Semaphores and taking advantage of a new KM v11 feature in the Pause Until action.

My technique used to be to create a global variable to keep track of the "state" of a Stream Deck button. This way I could know what to do when the user pressed the button. If the state was ON then the button would turn the state to off, and vice versa. But global variables are a pain to track and manage, and so today I tried to find a new way to achieve this, and I have succeeded.

Instead of using a global variable to track the state of a button, I can now use the existence of a running macro to track the state, and a Try/Catch action to decide whether the button should be turned on or off. Now with v11, there is an improvement to the Pause Until statement which reduces pressure on the CPU based on how long the Pause statement is running, which makes this approach more viable. Prior to KM v11 this approach would have to be made less responsive because you don't want macros running in an infinite loop, but the Pause Until action in KM v11 addresses this issue.


If anyone can see a flaw in this approach, or if anyone has a different way to solve this problem without a global variable, let me know.

The one downside to this approach is that if you either (a) stop/start your Mac, (b) start/stop the KM Engine, or (c) Cancel All Macros, then the "state" will default to "off" and the next time the user presses the button it will turn "on" regardless of its current state. That may be acceptable to many people.

It would be better if KM had an action that let me "read" the label on the Stream Deck button, but it doesn't seem to have that. Is there a reason for this omission?

Just curious... What deficiency in Stream Deck's own toggle function or the use of KM global variables that drove you to seek an alternative approach?

Global variables are a pain to track and manage. For the last few months I've use them all the time with Stream Deck Mobile, and with 32 buttons to press, that means 32 global variables. There should be a way to determine if a Stream Deck button is "on" or "off" (most buttons, the way I use them, toggle a state from on to off). But KM has no way to "read" anything from a button such as its text label. If KM had a way to read the label of a Stream Deck button, I would definitely use that to store the state of the button. Do you have any idea why KM cannot read that value? Does the Stream Deck API prevent an app from reading that value? Is this a limitation of the hardware, or did KM just decide not to provide that capability?

1 Like

No idea I'm afraid.

What about the native hotkey or multi-action switch buttons on the Stream Deck? They added the option to remove the green tick animation, which was the main drawback with that approach.

Thanks for enlightening me on the multi-action feature. I'll mention that in my last paragraph, below.

In my opening sentence I said "Stream Deck Mobile software for iPadOS." This means it's not Stream Deck hardware, but software running on iPadOS that emulates the entire hardware device. As far as I know the emulation is 100%.

The Stream Deck Hotkey action simply emulates a keyboard key, which I can already do with KM.

However you got me playing with the "multi-action action" in Stream Deck, and it appears that I can drag KM actions into that action, so that may be what I need! It seems to use "virtual numbers" for RnCn designators, (eg, R999C999) which is also something brand new to me. But I don't see an option to remove the green check yet. Anyway, thanks for bringing this to my attention, it's new and exciting.

Yes but there's also Hotkey Switch which toggles between two hotkeys. Handy on occasion.

1 Like
Uncheck the “Show progress overlay” option to remove the green check on multi-action buttons. (click to expand/collapse)

1 Like

Thanks. Whoever writes this user interface doesn't test it very well against new users. I would have said something more accurate like "Show Huge Green Checkmark."

1 Like