Can you use the next item in a Variable Array after every Macro repeat/loop?

I have a macro that I want to loop forever. This macro contains a list which I'm turning in to an array of variables. Each time the macro repeats or loops (not sure the best way to handle this) how can I set it to use the next variable in the array?

I tried to piece together a few different example macros I found but I'm not able to get it working.

Here's a really basic example I mocked up similar my setup. Currently it just keeps pasting "1" into TextEdit.

Paste # to TextEdit - Increase on Loop Macro (v9.2)

Paste # to TextEdit - Increase on Loop.kmmacros (3.6 KB)

A KM array by default is delimited by a comma. To use a custom delimiter, you need to specify it. I don’t think linebreak can be used as a text delimiter. You have to replace that with a custom one, or to use perhaps script to get the nth line.

See
https://wiki.keyboardmaestro.com/manual/Variables?s[]=array#Variable_Arrays

Oh shoot, that's right. I have that in my original Macro, I just forgot to set it up in my mockup example I shared.

I've fixed that issue in the mockup, here's the update. Note, now it pastes "10" 10 times in TextEdit.

Paste # to TextEdit - Increase on Loop Macro (v9.2)

Paste # to TextEdit - Increase on Loop.kmmacros (3.6 KB)

A couple of issues:

First, as the wiki page says:

β€œ<IndexNumber> ” is an integer indicating the index (starting with 1) of the array value within the Variable Array.

Therefore, you need either set the initial value of i to 1 or move the i = i +1 to the top of the loop.
The index 0 will output the count of the elements in the array, which is 10.

Second, you need to move the set variable currentNumber to the loop. When it is outside the loop. You will always get the count of the array.

Third, you don't need this set variable action at all. You may simply insert the text by pasting: %Variable%myNmbers[i]%.

Hell yeah, that did it. Thank you so much for the info.

Here's the macro for the people of the future, to avoid being a DenverCoder9:

Paste # to TextEdit - Increase on Loop Macro (v9.2)

Paste # to TextEdit - Increase on Loop.kmmacros (3.3 KB)

1 Like

I don't know what your real world use case is, but in general that is a bad idea.
If you need a macro to run on a regular, periodic basis, then use the KM Periodic trigger.

Ah that's great, thank you for that, I was not aware it was a thing.

So essentially KBM will be used to simulate an Agent in a Call Center environment. Other third party tools are used for standing up the call and performing the caller functions, but I needed something for the Agent side.

Once I get a PoC setup using KBM I'm going to have a standalone machine with a few VMs on it where, throughout the day, calls will come in and test the functionality of the environment. If there are any interruptions to the call flow there is reporting done and alerts sent out which we can then use to research the issue.

Because this is an environment that runs 24/7 I would prefer KBM to always be in a ready state, waiting for the call to come in (which I have working 100%) and having our other tool that I use for reporting and customer interactions control the call flow.