Progress Bar with Percent Complete Macro (v10.0.2) and related comments

I thought it would be interesting for people to see what happens when you nest two loops in each other and inside the second loop display a progress bar. In addition, the title of the progress bar shows the actual percent complete. This seems to be the best way to handle progress bars in nested loops, however there is a built-in "Display Progress" option that can be assigned to each loop, but that method doesn't display multiple progress bars, so this seems to be the only option for nested loops.

In this example the outer loop runs to 99 and the inner loop runs to 100. This is on purpose so that the final display value is ((99*100)+100)/100 which works out to exactly 100 which closes the window. There are other ways I could use to close the window, but this seemed reasonable for this simple example code.

Progress Bar with Percent Complete Macro (v10.0.2)

Progress Bar with Percent Complete.kmmacros (2.7 KB)

I found it quite curious that there is only a single progress bar for the following action: (in the following case, the Display Progress flag in the action's menu has to be turned on.) This tells us that KM's engine calculates the complete number of iterations before even the first indicated loop begins. That wasn't what I expected... (but it's fine)

image

I learned one more thing. If the number of iterations is very large (eg, >10,000), I could see that the KM Engine starts the progress bar with a short blue line that bounces back and forth from left to right, over and over, until the total number of iterations has been pre-calculated. For a 5 megabyte text file, searching for the character "e" takes about 20 seconds (on an M1 Mac) of "blue bar bouncing" before the progress bar starts moving from left to right. I guess this is a good thing. It makes sense.

However I have uncovered one small problem with the built-in Progress Bar feature of the For Each action. And that is the fact that while KM pre-calculates the number of iterations before beginning the loop, KM does not have a token that lets us access that value. This means we can't display both the file name and the progress bar value in the following example:

image

In the above example I show how to display the name of the file using the Display Progress action, but you can't also show the progress value because there's no token for it. If instead you use the built-in Display Progress flag for the action, then you can't display the file name, so unfortunately you can't have both. It seems like a reasonable thing to want to display both text AND a progress bar value. If a token was available that gave me the total number of iterations, then I could have my cake and eat it too (i.e., I could display both name and number) although I might have to create a counter to make that work correctly.

1 Like