Help with macro for repeating action variables

Hello.
This is my first post here and before I do anything, I would like to say hello to the community.
I am a music producer and I use Keyboard Maestro extensively to program macros for Protools and other music related pieces of software.

I am wondering if anyone can help out with some advice.

I have created a macro, see attached, that makes selections for me as it goes down a form.
There are always 16 slots on the form. You click on each consecutive slot and choose which option you want by using the down or up arrows. (I have attached a screenshot of the form).
The trick is, I need to be able to define how many slots the macro performs the action on.
I have set up a prompt at the beginning of the macro for getting a user-defined variable. I simply input the number of slots that I want to fill.
As it stands, the macro uses 4 steps to accomplish filling an individual slot

step 1 position the mouse and click on first slot
step 2 type the down arrow the number of times needed for slot 1 to be populated correctly
step 3 hit RETURN
step 4 initiates a short pause

step 5 position the mouse and click on the 2nd slot
step 6 type the down arrow the number of times needed for slot 2 to be populated correctly
step 7 hit RETURN
step 8 short pause
step 9 position the mouse and click on the 3rd slot

and so on....

As it stands, the macro keeps going until it reaches the end of the 16 slots.
I would like for it to stop when it reaches the number of slots that I defined in the variable at the beginning of the macro.

so ideally it would be something like this

step 1 position the mouse and click on first slot
step 2 type the down arrow the number of times needed for slot 1 to be populated correctly
step 3 hit RETURN
step 4 initiates a short pause

step 5 if variable is less than 2, stop macro

step 6 position the mouse and click on the 2nd slot
step 7 type the down arrow the number of times needed for slot 2 to be populated correctly
step 8 hit RETURN
step 9 short pause
step 10 position the mouse and click on the 3rd slot

step 11 if variable is less than 3, stop macro

and so on....

Unfortunately it is not possible to contain all of this in a repeat action variable times action.
you can move through the slots with the up and down arrows and highlight them but you can't open the dialog to choose which option to fill them with without clicking on them and the only way that I can find to do that is to manually map each position and click with a Move and Click from the absolute position action.

59%20AM
04%20AM

<a class="attachment" href="/uploads/defaulpopulate layout.kmmacros (48.5 KB)
t/original/3X/f/1/f10c6423eeef7d535ac7a3d614e60b9ff3ff6de4.kmmacros">populate layout.kmmacros (48.5 KB)

You could use a For Each action with a Number Range collection, and use a preset variable with an array of Tab numbers, one for each slot, something like:

You might also look at whether you can use type-ahead instead of down arrows to select the entry from the menu, since that would be more robust.

And since the click location is always the same, increasing by 19 each time, you can use something like:

To answer your question, it is very simple to do the “step 5 if variable is less than 2, stop macro”, something like this:

So putting it together it might look something like this:

Hi Peter.
This is great! Thanks very much.
I was able to get 'step 5' to work perfectly.
I am working on getting the rest of the script to work. I am currently getting an error when I try to enter (Index-1) command. the '-1' shows up as red and breaks the script.
I will continue to refine and let ya know.
Thanks again

Hi again Peter.
Just working on this a bit more.
I've copied your script and I'm getting two errors47%20PM 33%20PM

I've attached the macro. I'm probably missing something simple here.
Thanks again for the help.
populate layout copy.kmmacros (7.7 KB)

It looks ok - remember it will be invalid if the variables are not currently set to valid values. Specifically, Index needs to be set to a reasonable value.

See how the “-1)” is orange, not red? It is orange because the calculation is currently invalid, but could be valid if Index had a different value, which it will do once you run the For Each action.

A post was merged into an existing topic: Repeating set of actions within a macro