Set Stream Deck Button Title to Different Variables Inside of Nested If/Then/Else?

I have a macro created, in which I am using an If/Then/Else action to tell KM to update a Stream Deck Button based on whether or not a particular condition is true or false. If the condition is true, it uses one variable and, if the condition is false, it uses a different variable.

Within KM, I can see that the correct value is populating in the bottom left corner of each of the two "Stream Deck Set Title" actions I am using. So each of these two actions appear to be correctly pulling the value from the variable I have assigned for them to use.

When the condition is true, it works the way it's supposed to, and uses the value from the variable indicated in the first instance of the "Stream Deck Set Title" action. However, when the condition is false, the button on my Stream Deck continues to only display the value from the variable in the first "Stream Deck Set Title" action, and not the second "Stream Deck Set Title" action. In other words, when the condition is false, it should be displaying Avl737 on the SD Button but, is instead, incorrectly displaying 175-B.

I've tried different things here, and I am just stumped as to why it's not displaying the value from the variable in the second "Stream Deck Set Title" action when the condition is false.

Any thoughts?

I've provided a screen grab of the macro below.

If you add a Display Text "made it!" (or whatever) inside the loop portion that's not executing, does the text display? (Just a stupid-simple test to make sure you're getting into the loop.)

-rob.

The second ("Otherwise execute...") section of this macro is not executing when the conditional is false, even though you can see in the screen grab pic that it is showing as false.

When I get rid of the variable and just put in plain text, it still does not populate the SD button with the correct title. Also, when I use the "Display Text" to test the macro, it also does not execute when placed in the second section of the macro.

So something is wrong here. I just can't figure out what it is. It seems like a pretty simple, straight forward macro, but the secondary section is just not executing when the conditional is false, and I can't figure out why that is.

Any ideas?

If the "otherwise" isn't executing, then Insert1MCUNameFinal must always be equal to Insert1MCUName. Without seeing the rest of the macro, though, there's no way to tell how/why that might be the case.

What are the values of the two variables just before the If/Then statement?

-rob.

This is a shot in the dark, but try changing the "matches" to "contains" and see if that works.

But as you can see from the screen shot, it's condition shows as false, so the conditional isn't matching 100% of the time. From my observations, it seems to be matching (true) or not matching (false) as I would expect it, based on the various scenarios I've tested it under.

I'll try to post the full set of macros so you can see everything, but I suppose your are asking about the variable values immediately before this if/then macro because of any concerns that might come from timing issues. To test that theory, I put a 1.5 sec pause immediately before the macro, to see if I needed to give things time to catch up, and it still didn't work.

I tried that too. No luck.

I'm sorry that didn't help. My reason for suggesting the change to "contains" is that "matches" doesn't mean "is equal to" but "matches the regular expression" (see the Conditions page in the Keyboard Maestro Wiki). So if your variable contains any of the regular expression tokens (e.g. the anchor symbols, or brackets) then you're going to get unexpected results.

However, as that didn't help, and as I can't see anything else in your action that might be causing it not to work as you expect, I must confess I'm stumped.

No, I actually just wanted to see those actual values from the macro's run.

-rob.

The match I'm asking KM to look for involves a simple six character (exactly six characters every time, by definition) name consisting solely of upper and lower case letters, as well as numbers. In theory, it could include things like brackets, but in practice, it won't. And it certainly hasn't contained anything other than letters and numbers for the scenarios I've been using to test the macro with. So using "matches" should work.

And, the thing is, that I'm already getting the behavior I would expect when I look at things in the editor. The macro already indicates "true" when I get a match, and indicates "false" when it's not a match. The problem is just that the "otherwise" part of the macro isn't firing.

I had thought it maybe could be a timing thing, so I still want to do a little more testing on that. In other words, maybe KM is cycling thru everything and gets to this particular macro before the variable values have had a chance to populate. In which case, that could momentarily cause problems for the conditional.

So when I've said that I'm getting behavior I'd expect, I should qualify that by saying that I'm seeing the correct true or false result when looking at the macro window in the editor AFTER I've run the action in the other app that triggers this macro. So I suppose it's possible that, if there are timing issues, the macro isn't getting the latest variable values in time to compare them, but by the time I switch windows to go have a look myself, the variables have finally had enough time to catch up and indicate true/false in the KM editor, even though it's too late at that point to get the "otherwise" section of the macro to fire.

I need to try this out with a second monitor so that I can watch the editor window real time to see how quickly the true/false condition is firing.

Ok. When I'm back in front of my computer later today, I'll post up the whole series of macros so you can see everything. I suspect that, hidden away somewhere in there, is the source of my problems, even though I can't seem to figure out what it might be.

I think the first step is to just add a Display Text action just before the if-then, and display the values of the two variables. When I do this, I usually do it this way:

Variable 1:
###%Variable%MyVar1%###

Variable 2:
###%Variable%MyVar2%###

The pound signs let me catch any leading or trailing spaces that might have crept into my variables, which would otherwise be invisible.

-rob.

Here's the full set of macros

Insert 1 MCU Button Display Text Translator.kmmacros (27.1 KB)

So, using the display text action, as you suggested, I'm not having an issue with any errant spaces or anything. But I'm not getting a display text window to fire in those instances in which I'm not getting a match. In other words, it's displaying a window for those situations in which I would have gotten a match in the subsequent macro we have been discussing. But, otherwise, no display text window is firing up. So the problem appears to be more deep seated. I'm still stumped as to why that is though, especially when I can see confirmation of the true or false status in the specific macro we have been discussing.

Can you post what the values are of the two variables?

-rob.

I can't. They are, by definition, very variable. Hence the nature of MCU variables. They are, by definition, changing all the time.

I'm confused: I'm just asking that you show the output of a Display Text action inserted right before the If/Then. Certainly they can't change between that action and the if/then?

And I have no idea what an MCU variable is, sorry.

-rob.

Sorry. Let me clarify.

No such window with the variable values pops up when placed immediately before the if/then, in cases where I would ultimately be seeing an indication of "false" in the subsequent if/then macro. That's why I was saying I can't tell you what those values are, based on what might be popping up in a window. It's because there is no text display window popping up in those situations.

It's unclear why that might be happening though. I can clearly see values populated for those variables at various points in the overall set of macros, so I'm stumped why it's not recognizing them and displaying them in a window when they clearly are defined and exist?

As for MCU, it's just a communication protocol based in MIDI for hardware controllers to talk back and forth with the software they are being used to control. So what I am attempting to do with these sets of macros is to manipulate the feedback data that the software is trying to send to my Stream Deck.

These set of macros look up the hexadecimal numbers in a lookup table I've created, and then translate each number to a corresponding character, based on predefined translators used as part of the MCU protocol (You previously helped me with the Regex on some of this). Once translated, I'm then assembling those individual characters together into a six character name used for each of eight title slots to be displayed on my Stream Deck. At that point, the MCU name exists as a variable called %Insert1MCUName%. The other seven title slots are accordingly named %InsertXMCUName% where "X" is a number 2 thru 8.

Furthermore, I then have a separate lookup table where a user can define "long" names to be used as a translation from the six character MCU name. This is because, though the six character MCU names are each unique, it still can be a little difficult to tell what is what when some of the MCU names are similar, given their short, abbreviated nature.

So what I'm trying to do with all of this is to have the Stream Deck display the six character MCU names by default, when a user has not yet defined long names in the translation lookup table, but otherwise display the long name when a user has added the long name translator in the lookup table. This is the basis of the particular if/then macro that I've been asking you about here in this thread.

In a nutshell, it is displaying the long name, as it should. However, it's not defaulting to the MCU name when a long name is not defined in the lookup table, even though I can see within the set of macros that it is correctly identifying and assembling the MCU name and assigning it to the %Insert1MCUName% variable.

So looking at the screen grab that I provided one of my earlier posts, my Stream Deck should be displaying the six character MCU name of "Avl737", because I don't yet have a long name defined in the translation lookup table. Instead of displaying "Avl737", it is displaying "175-B Comp", which is the long name I've defined in the lookup table for the MCU name "175BCm".

What appears to be happening here is that it correctly assigned the value of "175-B Comp" to the variable %Insert1LongNameFinalSDButton%, based on what it looked up in the table when that particular channel in my software was selected. However, when I changed channels in the software, to the channel that had the Avl737 on it, it went to look for the long name translator, but upon not finding it, didn't update the variable %Insert1LongNameFinalSDButton% or the Stream Deck to the default value of Avl737. It just kept the value of "175-B Comp", as previously assigned. In other words, it's not recognizing the need to update the variable. So somewhere in there is where the breakdown seems to be happening, though I can't figure out why.

Hopefully this helps explain it better.

In the screenshot in your first post I notice that you are using global variables. Those variables persist when your macro isn’t running (you can see them on the variables tab of KM's preferences).

If you’re not initialising those variables every time you run the macro, then whatever value they last held will still be there and be used in your macro.

Is is possible that, even though there is nothing in your look up table, the variable is still populated from a previous run and thus your if/then is always true?

Is that within a previous if/then or case statement? The window should definitely pop-up, even if the variables don't have values. If you're not seeing the window, then something in the flow is preventing it from even reaching the if-then.

-rob.