'Display Progress' Menu Option for Groups Action? (Already Works With 'For Each' Action)

Okay, thanks. I stand corrected. I apologize to the world for being partly wrong.

Okay this is what I have and I tried a few more things but I am not sure what is wrong. I see the numbers increasing in the Value Inspector for the variable "ProgressPercent" but no window.

This makes more sense now you put it in a repeat loop that each time it is run the value increases and you choose to set the repeat to "Display Progress" though if it was showing you everytime it was repeating then there would of course be no need to make a counter that changed since the Repeat Action is basically handling that for you, if I understand right.

Progress Bar

***Testing Playground Macros.kmmacros (89 KB)

I tried it both ways with

and with

Clearly I am missing some key concepts here.

So two ways besides the AppleScript that I am already doing if I understand right. This is what I have uploaded in this post that is not working.

This is beyond me and I would need to see an example of this to understand what you are saying.

I agree with both of those. It is very neat and in my reference macros for the future. I hope to use the progress bar in better ways in the future and not just on repeat or group actions with the cog wheel option to "Display Progress."

Your first image looks like a correct copy of my asynchronous macro, so it should work. Your second copy changed the Local1 variable to a global variable, which is a pretty risky approach and may not work in certain situations. You shouldn't change that, for safety reasons.

As for your AppleScript, I will ask if Nige can test that. I'm out of time tonight to examine it, and in any case he knows AppleScript much better than I do.

Here you go. Nice things about this method are that it's self-contained and uses a local variable:

Async AS Progress.kmmacros (3.8 KB)

Image

When you run it for the first time ever, what's the initial and end values of the global ProgressPercent? When you run it for the second time, what's the initial value of ProgressPercent, and what does that mean with respect to the "Global Counter" macro?

My apologies, that one is working with the code I posted above and I have been using that.

Good to know, I thought the Local1 was the way to go but it wasn't working so I tried many things but those are two of the things I tried and posted so it didn't get too harry showing all the things I did that didn't work. Thanks for the reply.

That's cool; I do like it when they are self-contained like that and do not reference other macros unless several macros need to reference it so I can change it in one place.

It always starts at zero.

Rename/Modify Names - (R) Prompt to Replace Text for All Selected Macros (Feedback for Progress Bar) - Test Async Macro

Rename - ProgressPercent

01)Rename-Modify Names - (R) Prompt to Replace Text for All Selected Macros (Feedback for Progress Bar) - Test Async.kmmacros (47 KB)

Great question, and that is what I have not been able to make any sense of. I don't understand how running the Golobal Counter macro will get its information from %Variable%ProgressPercent%.


Referenced macro

I thought maybe the token %TriggerValue% was somehow pulling it while it was running and doing calculations asynchronously, but I wasn't really sure.

Ah, but it doesn't -- at least, not in your test macro above.

When the AppleScript starts it sets ProgressPercent to 0 -- when it finishes, ProgressPercent is 100. When you next run the macro you call "Global Counter" before the AS action -- ProgressPercent is still at 100 so the progress display is already complete (setting the progress bar to 100 is what closes the dialog).

You need to zero ProgressPercent before calling the "Display Progress" macro.

Global Counter uses the parameter passed to it -- in this case, the text "ProgressPercent" -- in the "Filter" action. That's what the %TriggerValue% token is for.

So the literal translation of your "Filter" action is:

"Set the value of the variable Local1 to the value of the variable named ProgressPercent."

The whole construct makes the "Global" macro more black-box. Instead of requiring that any calling macros use the global variable "Global" expects, your calling macro is saying "And this is the global variable I want you to watch".

1 Like

Ah that makes absolute senese! Eureka!

Working on the easy update now (knock on wood), just one ation set veriable ProgressPercent to 0. Problem solved!!!! Thank you that was it, I didn't realize that is what was dismissing the window. I love moments like these, that makes so much sense and logic I wasn't seeing because there were so many other things I was not understanding for certain. Thank you!

It could be just the way I am updating the progress window through AppleScript but keeping it in Keyboard Maestro seems to be about 4 times faster.

AppleScript progress window.
Rename - ProgressPercent - AppleScript

AppleScript Directly Updating Keyboard Maestro Progress Window

01)Rename-Modify Names - (1) Prompt to Replace Text for All Selected Macros.kmmacros (51 KB)

Keyboard Maestro Macro Progress Window getting values from AppleScript sending to the variable "ProgressPercent"

Rename - ProgressPercent - Working

For anyone else here is the working macro with one extra action added of set "ProgressPercent" to zero. I think I will use this for the other renaming macros and add that reference macro to the mix.

ProgressPercent - Working - Reference Macro

***Testing Playground Macros.kmmacros (89 KB)

Keyboard Maestro Export

My guess...

(Almost) Every time you send an AS command to an app, the script waits until that command has been executed and the app has returned a result. So your first macro waits after every name change for the Engine to "create" a macro from the XML, execute that macro, and tell the script "Done that!". The second only waits for the Engine to update a variable, which is much quicker.

As so often you're balancing speed, complexity, ease of maintenance, etc, etc -- so go with whatever works for you.

Makes sense, I didn't realize the AppleScript was waiting for a reply back to move forward. That certainly would slow things down.

Absolutely good to see what is quick versus what is self-contained and fast. I love both approaches and thanks to you guys have added them both to my bag of tricks. Thank you very much!

Simple Keyboard Maestro AppleScript Progress Bar

**AAA - Automation - Keyboard Maestro - Reference Macros - :star::star::star::star::star: Macros.kmmacros (87 KB)

tell application "Keyboard Maestro Engine"
  -- Initialize progress
  setvariable "ProgressPercent" to "0"
end tell

repeat with i from 1 to 100
  -- Update progress variable
  tell application "Keyboard Maestro Engine"
    setvariable "ProgressPercent" to i as text
  end tell
  
  -- Small delay to allow UI to update
  delay 0.1
end repeat

Glad I could help. I kept my approach simple, but it can be upgraded to allow for both a variable name and a text message to replace the phrase "Keyboard Maestro Progress." It could also be made simpler by just having a "bouncing progress bar" and that could be done without a variable at all.

That sounds very interesting I looked that one up and this is the only thread that had anything about that. If you have a macro you can share I would love to see an example.

To make that happen, just use the macro I posted above, but change the "Progress" field in the "Display Progress" action from "Local1" to "-1".

Oh, and one more thing, at the end of the macro you have to add this action: (otherwise the bouncing progress bar window will never close.)

image

1 Like