Unable to execute a macro with name from the variable

The macro is does not trigger the macros it intended to.

Basically any of the items on HTML menu that are clicked should be checked for "clicked" = 1 condition and the ones that clicked should run the macros.

What am I doing wrong?

Here is the part of the macro screenshot:

#Orders HTML Prompt.kmmacros (36.7 KB)

The code I gave you in your other post was from my plugin action and you’ve tried to use it in an execute AppleScript action which is why it isn’t working.

The line

set _Macro to system attribute "KMPARAM_Macro" as text

is incorrect in that context so you have to revert to what you had previously

set MacroToRun to getvariable "VarName"

but inside the tell application "Keyboard Maestro Engine" like this

tell application "System Events"
	with timeout of 36000 seconds
		tell application "Keyboard Maestro Engine"
			with timeout of 36000 seconds
                set _Macro to getvariable "VarName"
				do script _Macro
			end timeout
		end tell
	end timeout
end tell

I'm not at my Mac so can't test for you but hopefully it will work as intended.

Alternatively - install the plugin action I posted (the zip file) and use like any other KM action. It's much neater and you can use it with any variable! Here's an example of how I use it:

@tiffle something still does not work, also the plug in action is not downloadable. Any chance you can look at it further when you have a chance?

What do you mean by that?

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)?


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:


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:


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