Unable to execute a macro with name from the variable

Or I see - I was looking for zip file in this thread, but it was in the previous thread - found it!

@tiffle - installed your action, and unfortunately it does not work either:

The first time through the loop you set VarName to local_A1.

Then you test VarName for equality to 1; but of course it doesn't equal 1, so the plugin is not executed.

End result: nothing happens.

Not sure I am following.
If you check the HTML script, it has a list of check boxes like these:

<input type="checkbox" id="localA1" name="localA1"><label for="localA1">CBC</label><br>
<input type="checkbox" id="localA2" name="localA2"><label for="localA2">CMP</label><br>

So If I check the checkbox, then local_A1 = 1, then if I assign VarName to local_A1, it should be equal to 1, no?

Can’t do that as I’m not at my Mac - remember?

No. If you assign VarName to *%Variable%local_A1% then it will equal 1 but only if local_A1 itself contains 1. Just look at your Set Variable action - at the bottom it has local_A100 -> local_A100 which shows what VarName was last set to when you ran the macro; it’s clearly not what you are expecting.

BUT - I’m not familiar enough with Custom HTML Prompts (if that’s what you’re using) to be able to advise you on getting values from them into KM variables.

I can guarantee that the plugin works - well, after 6 years using it myself I’m pretty confident on that, which was your original question. It’s now up to you to get the correct value into VarName.

No. Your HTML is referencing a Variable called "localA1" which is not the same as a Variable called "local_A1"

Also your Action:

This will not set the contents of VarName to 1 or 0 because it Is literally setting the actual text contents of VarName to the text "local_A1", "local_A2" etc all the way up to "local_A100". You can see this by the fact that the last value shown for VarName is "local_A100"

You are trying to make a dynamic Variable - which is not that simple to do in Keyboard Maestro. When I looked into this a while ago I ended up using a Keyboard Maestro Dictionary instead.

1 Like

@Zabobon thanks for pointing out local_A1 vs localA1 - I've obviously missed it.

Also appreciate learning about dynamic variables. I've used an easier solution, as it was hard for me to comprehend Peter's dictionary use example right away.

Here is my latest implementation - both Dynamic Variables Names and Values seems to be working.

However I can not make the macro run based on dynamic variables name - neither via AppleScript, nor using @tiffle plug in.

#Orders HTML Prompt.kmmacros (40.3 KB)

Out of curiosity, what are the names of the macros you want to run using the plugin action (or the AppleScript)?

localA1
localA2
Etc

But they are the names of variables containing “0” and “1”.

I’ve never used a variable whose name is the same as a macro (I didn’t even know that was permitted by KM) so I don’t know what KM will do with that.

I suggest you give your two macros other names like “MacroA1” and “MacroA2” and modify the action where you set VarName appropriately.

Changed the names of the Macros to MacroA1 etc. and added pauses.

Still does not work.

@peternlewis, what am I doing wrong?

What does the KM log file report?

@tiffle, good point - I've rarely used the log, and forgot I can troubleshoot using it.

The error is that it does not find the matching macro, even though both macro and macro groups are enabled, it is similar error using your plug in:

2023-06-30 07:52:19 Execute an AppleScript failed with script error: text-script:85:105: execution error: Keyboard Maestro Engine got an error: do script found no macros with a matching name (macros must be enabled, and in macro groups that are enabled and currently active). (-1). Macro “###NextGen Menus” cancelled (while executing Execute AppleScript).

I've just tested your macro and here's the output from my debugger:

2023-06-30_14-14-38

So all that's OK but of course, the macro then failed because I don't have a MacroA1 - with the same error as you've seen in the KM log file.

So I created a simple MacroA1 that just displays a text message (so I know if it runs) and when I tried again, it failed again with the same error!

Looking more closely this is what I found:

2023-06-30_14-20-25

Your macro group is not enabled.

When I enabled the Macro Group and ran your #Orders HTML Prompt macro again, it all worked fine.

Even though you said:

I'd check again to ensure everything is enabled.

All groups are (and where) enabled

Screenshot 2023-06-30 at 8.26.57 AM

OK - in that case there must be something wrong with how you've named your macros.

Can you upload a copy so I can take a look?

Scrub that - I think I've found the problem.

In your z Orders for HTML macro group you have this:

2023-06-30_14-42-33

When I have that my test fails, but when I switch it back to this:

2023-06-30_14-44-20

It works again. Try getting rid of that "Available in these applications" bit and see what happens.

Sure. Here is the last iteration of the main macro and the submacros. The last macros are in the group called "z List of Labs NexGen" which is enabled.

.CBC.kmmacros (1.5 KB)
.CMP.kmmacros (1.5 KB)
#Orders HTML Prompt.kmmacros (41.2 KB)
localA1.kmmacros (1.8 KB)
localA2.kmmacros (1.8 KB)

Screenshot 2023-06-30 at 8.46.50 AM

Re: your last finding - it was available in Citrix Viewer before, and I was in the process of deleting it to allow in all apps, but snapped a picture too early. It is now available for all apps.

P.S. during troubleshooting I also just created two localA1 and localA2 macros (now deleted) with only component in use - display large text "It worked!" to make sure a chain of execute macros is not the issue - still didn't work.

Could it be that the local variable does not work outside KM?
Although VarName is not local...