Repeat Actions With Variable Value

Set the variable value, repeat the number of +1, and update the variable.
It is very difficult for me. Is anyone willing to help me?
image

I need to repeat the action "Type the Right arrow Keystroke" up to 20 times.

The usage scenario is like this. There are a lot of videos in the folder that need to be uploaded to the website. You can only locate the first video each time you upload. I want to use Keyboard Maestro to select video uploads automatically.

image

I'm not sure I understand your video uploading workflow, but assuming this is the best/only way to accomplish this task, here's an example macro that will prompt you for a folder, then type the right arrow key for as many files as are in that folder automatically:

Repeat Action for Number of Files in Prompted Folder.kmmacros (3.7 KB)
image

The admittedly un-intuitive trick to this is that you need two repeat actions: one for the count of video files, and one to perform the action that number of times starting from one.

1 Like

Thank you so much! The problem is solved! You saved a lot of time for me!

1 Like

You're welcome. Glad to hear it solved your problem. However, in the interest of optimization, I realized after I uploaded that macro that it was a little redundant, and it could be made to work just as well without the VideoCount variable:

Repeat Action for Number of Files in Prompted Folder 1.1.kmmacros (2.9 KB)
image

1 Like

Thank you!

I keep coming across this solution that I would like to implement. I have KM ask for user input and set it to a variable.
Then I try to put that variable into a repeat loop, but the sample on this forum indicate the number in repeat can be replaced with the variable. My KM throws an error when I do that.

Also, my KM Repeat Actions icon is different than the one in these samples on the forum.

image

Mine:

mine

if you actually run it does it work?
The Repeat Actions says "Currently invalid" this most likely means that the variable doesn't exist yet. When you run the macro, the prompt will create the variable and the repeat will then work correctly.

Since you're using a global macro once executed once the variable will exist from then on and the message should go away.

1 Like

Hey Stephen,

Welcome to the forum!   :smile:

In future please post the smallest possible test-case macro and all related files and/or images that illustrate your problem.

This is easy to do using the Keyboard Maestro Editor's Share-to-Forum command, although it takes a couple of practice runs to get used to how it works.

You can zip and drag and drop any additional items into the forum editor.

How to Post Your Macro to the Forum

Trying to recreate what you've done is hit or miss at best, and most folks won't bother. The easier you make it to test your work, the more likely you'll get quality help in expeditious fashion.

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?

As @kvanh asked:

Did you actually run the macro?

Keyboard Maestro will display errors in a variety of conditions that don't exist when a macro is actually run.

It's a good practice to test-run macros using a simple keyboard shortcut like F1 rather than mess around with TRY in the editor – at least until you know exactly what you're doing.

Here's a working example.

User Prompted Repeat Example v1.00.kmmacros (7.0 KB)

You'll note that Keyboard Maestro appears to be throwing an error. What it's saying is actually true, but it's not an error (as @kvanh explained).

-Chris

1 Like