Issue with "Repeat" Action Not Accepting Variables Beyond the First One in Keyboard Maestro


I've encountered a problem while trying to create a macro that involves multiple "Repeat" actions, each supposed to run a different number of times based on user input. I used the "Prompt for User Input" action to define three variables: RepeatTimes, RepeatTimes1, and RepeatTimes2, with all default values set to 1. My intention is to use these variables to control the number of repetitions for three separate "Repeat" actions within the same macro.

The first variable, RepeatTimes, works perfectly, and I can use it to control the repeat count of the first "Repeat" action without any issues. However, when I attempt to use RepeatTimes1 and RepeatTimes2 for subsequent "Repeat" actions, they don't seem to work. Specifically, when I set the "Execute these actions" field in the "Repeat" actions to RepeatTimes1 or RepeatTimes2, Keyboard Maestro displays a "currently invalid" error for these variables, indicating they are not recognized or cannot be used in this context.

I have double-checked the variable names for typos and ensured they are declared before their usage in the "Repeat" actions. Despite this, only the first variable (RepeatTimes) is accepted, while the others lead to an error.

Could anyone please provide insight into why this might be happening or suggest a workaround? I am looking to have each "Repeat" action respond to a different variable input from the user, allowing for dynamic control over the repetitions of these actions based on user input.

Thank you in advance for your assistance!

Can you upload the macro so we can see it? It's tough to tell just by looking at that screenshot.


Hey sophisthide, I'd suggest run the whole macro again and click "OK", then the default values (1) will be stored into the Variables. You'll get the "currently invalid" message if the Variable hasn't been defined. My guess is you tested it with 'RepeatTimes' as the only option so it stored the value of RepeatTimes=1, and when you added the additional repeats with Variables 'RepeatTimes1' and 'RepeatTimes2', you got the error. Hope that works!

1 Like

As @gmonmo explains, the current value of the RepeatTimes1 is invalid (more accurately, the numerical expression RepeatTimes1 cannot currently be evaluated because of the value of the RepeatTimes1 variable).

Check it's value, or alternatively, set it to a valid value.

I'm working with Keyboard Maestro and utilizing the 'Prompt for User Input' feature to create dynamic macros. Specifically, within the 'Prompt for User Input' menu, there's an option to define variables and their default values. For example, I set up a variable named 'repeat times' with a default value of 1. My goal is to use this variable to control the execution count of a repeat action. Whenever l initiate the repeat action, a prompt appears allowing me to specify the number of repetitions. My question arises when considering the implementation of multiple repeat actions within a single macro. If I wish to have two or more repeat actions, can I set up the 'Prompt for User Input' in such a way that each repeat action can have its individual repetition count specified at runtime? Essentially, l'd like to activate a macro containing several repeat actions and have a prompt appear for each, allowing me to set different repetition counts for them separately. Is this feasible within Keyboard Maestro? If so, could you please guide me on how to configure this setup correctly? I'm looking to enhance the flexibility of my macros by allowing varied repeat counts for multiple actions based on user input at the time of execution. Thank you in advance for your assistance and insights!

If I understand this request, it's as simple as using as many Prompt for User Inputs as you need, one before each Repeat section. But you wouldn't input three values, just one value for the upcoming repetition. And because you want these things to change every run, there's no need (I don't think) for you to keep their values around as global variables—you could use instance or local prefixes to have Keyboard Maestro automatically clear them after every run.


Thank you so much for your guidance! Following your advice, I was able to successfully implement the functionality I wanted in my macro. Using multiple 'Prompt for User Input' actions before each 'Repeat' action and utilizing local variables for each repetition count was the key to solving my issue. Your clear explanation made it easy for me to understand and apply the solution. I appreciate your help and patience. This community's support is invaluable to me. Thank you again!

Glad it's working for you!