Bug in %PromptButton% in KM 10.2?

This macro works standalone. But when it's embedded in a more complex macro, %PromptButton% always returns the null string. I think there might be a bug in KM 10.2.

Bug in Prompt for User Input?.kmmacros (3.3 KB)

Macro Image

image

I was able to produce what I assume is your expected output with the below macro.

It may be worth noting that using %Variable%PromptButton% instead will not give a result, as %PromptButton% is a "token" (which is conceptually in the same class as "variable", a separate token).

See the wiki documentation on PromptButton and Tokens.

If this doesn't fix your issue, can you upload an example of the more complex macro that's doing the embedding?

Cheers,
Vito

Test Prompt Button.kmmacros (2.4 KB)

It will depend on how you are "embedding" the macro into your larger workflow.

%PromptButton% is scoped to the executing instance -- @avtraino's example works because the sub-macro is part of the same executing instance as the parent, but if you change the "Execute Macro" action's option to "Asynchronously" you'll get your null value in the display because an async sub is a new instance.

1 Like

Thanks for the help.

Unfortunately, I can get the simple stuff to work fine. I don’t know what the problem is, really, and I’ve eliminated the problem with the project I’m working on, so I really cannot do what you ask.

One thing that occurred to me was whether or not having two separate “Prompt for User Input” in the same macro works or not. Both use the %PromptButton% token, and I’m wondering if KM somehow gets confused….

So, if I have only one “Prompt for User Input” in the executing macro, and lump everything into that, it should work OK? That would be about 5 variables, and a single “OK” for the whole thing.

There’s also two large AppleScripts in the macro, but I wouldn’t expect that to have any negative effect. There’s an easy way to pass parameters from KM to AppleScript, but it’s a little tricky since you have to scope the “tell blocks” if there are multiples of them:

For example, if startngAt and endingAt are two KM variables, I can shadow them in AppleScript this way:

tell application "Keyboard Maestro Engine"

set startingAt to value of variable "startingAt"

set endingAt to value of variable "endingAt"

end tell

I’ll try it when I get a chance.

According to my testing, you can have as many such prompts as you want, but they will overwrite %PromptButton% as soon as they execute.

You would need to handle the result of the first prompt before the second prompt action runs.
One option would be storing the values in variables so you can use them at your leisure.

1 Like

Thanks, but for the record, I was using %PromptButton% immediately following the command, so no need to store it.

Should do -- but it's difficult to say without seeing an actual macro. If you could post something that's going wrong we'd be able to troubleshoot things better. For example, I'm not clear what you mean by "embedded in" in your OP -- have you pasted those actions into the macro, are you calling the sample macro as a sub-macro or subroutine, from an AppleScript action, something else?

What we can say is what's in the docs -- that %PromptButton% is scoped to the executing instance. It's more likely that you're going "out of scope" than that there's a bug in KM. And I'm thinking that's even more likely if you are having to use global rather than instance or local KM variables in your AppleScripts.

1 Like

Pretty sure this demonstrates that there is a bug in buttons:
note the names of the buttons in these two images:

Note what happens when I run it:
Screenshot 2023-03-14 at 1.48.24 PM

This will be very difficult to reproduce unless you post an actual macro that demonstrates the problem -- we've no way of knowing the complete URL from your screenshot, for example.

I can sort of reproduce it by pasting

OK

--

OK

...into the action's "OK" button field, but I'm sure you haven't done that! So please post a demo macro.

1 Like

Since I've restructured my code to work around this problem, that will be difficult. But I will post the macro when completed. There are some very large applescripts.

If you have two Prompt for User Input actions in the macro, presumably they would execute in series, and so the results for the first one (eg the PromptButton token) would be valid for the remaining macro until the second one executes.