Execute different actions depending on which Stream Deck button is pressed?

I have a set of macros I use with OmniFocus to assign tasks to projects while processing the inbox. The Project A button on the Stream Deck starts the Project A macro that goes to the project field and enters the title for Project A. Same with Project B, C, etc.

Instead of having a separate macro for each project title, is there a way to have logic in just one macro that enters the title, depending on which Stream Deck was pressed to call the macro? (If this button was pressed, paste this text... If that button was pressed, paste that text...)

I don't see a way, because the Stream Deck Keyboard Maestro action or the KM Link action would have to send something to the Keyboard Maestro engine that indicated which button (row, col, button ID?) had been pressed, and the engine would have to notice that indication.

Ideas? Some other way to approach this?


1 Like

I don't have a Stream Deck, so I can't test this, but there's a chance that the %TriggerValue% token contains the name of the button. Why not display this token in your macro to see if that holds the information you need?

I just tried this with a different USB device, not the Stream Deck, and I got the name of the key. So it might work for you too.

Sleep is spot on. If you use KM Link to trigger your macros then you can assign a parameter which KM can use to do different things according to that parameter.

For instance, I have a bunch of buttons assigned to play different music playlists. In the parameter field I put the name of the playlist, and in the macro itself I use %TriggerValue% token to play that playlist.

Stream Deck screenshot (click to expand/collapse)

Macro screenshot (click to expand/collapse)

Thanks. This is the second time today that I've been recognized for something. Maybe I should quit while I'm ahead.

1 Like

I think I get what you're suggesting, but I still don't have something quite right. Just trying to test the concept, here's a macro that's getting no response:

Of course, I put SI-Me in the Stream Deck parameter field for this button.

One thing that looks likely to fail here is that you are using a Set Variable to Calculation action instead of a Set Variable to Text action. That could work if the %TriggerValue% returns only a number, but since you didn't tell me what %TriggerValue% could be, that's a very risky thing to do. Please replace that action with a Set Variable to Text action and let's see if that fixes it.

Technically, you don't need to create a variable at all. You could modify your IF statement to check the value to the trigger instead of a variable, but there's nothing wrong with your approach.

The thing that I think you haven't quite grasped yet is that, while all numbers are strings, not all strings are numbers. That's why your first action is likely to fail.

Well now you're two for two! :grin:

Sleepy is spot on again. Here's a screenshot to show what he's referring to:

I've got it working now, thanks to the generosity of you all. Now that I understand using if-then, I'm moving to a stack of Switch/Case actions, one for each project title, in just one macro. This will tidy 10 separate macros into one that will be much easier to maintain.

Please let me know if there's a better way than switch/case, but it seems like this sort of thing is what it's for. Better than a tangle of nested if/then actions! :slight_smile:

Glad you got it going! And you are absolutely right about using the switch action... I use it for this kind of thing all the time and it works great. Especially as the "otherwise" option works just like the "else" action of an if/else action.

The Switch action issue wonderful, and so is KM, but I must tell the truth, the KM Editor gets bogged down (slow) if you have more than about a dozen blocks in the Switch statement. When I've used 20-30 blocks in a Switch action, the KM editor has become almost unusable. (But I don't think it impacts the speed of the running macro, so it's not a problem at run time.)

Hey Sleepy. With respect, the slow-down you're seeing may be the result of something other than the pure number of case statements.

I've got macros with about 30 switch statements and they are pretty fast. (Each switch is comparing with the name of a running application and loading a named clipboard with an external image.)*

Remember, each call only tests until it succeeds, some some of your calls should be pretty quick if it's really the case statement.

*Why the heck am I doing this? I needed a default stream deck profile for when the current app doesn't need a custom profile. So I build a dynamic array of all the running applications and I can use the deck to switch to any one of them. WAY too much work if you don't have OCD, but sometimes I have over twenty running at once and it makes me smile.

1 Like

I have a macro that has two switch actions in it with a total of 201 statements. :scream: It contains client information so when I receive a call another macro reads the call info and this one pastes the information of whoever called me into my notes. The Editor still runs fine with it.

Okay, then I don't know what it is about my Switch statements that isn't scaling well. I could investigate, maybe another day.