Looping Actions Until a Condition Is Met

Hello and thanks for your help!

I don't understand why I'm struggling so much with such a simple concept. Let's say that I want to add "1" to filenames in a folder, BUT I want the loop doing this action to stop as soon as it sees a file named "STOP".

I tried the While action, and the If one, they don't seem to work in this case.... I'm trying to use the Clipboard condition, telling KM to stop if "STOP" is in the clipboard

Screen Shot 2022-09-09 at 10.16.23 PM

There are a few ways to do this. Here's one, based on what you already have:

Add "1" to Filenames Until "STOP".kmmacros (26 KB)

Macro screenshot

Here's another:

Add "1" to Filenames Until "STOP" v2.kmmacros (22 KB)

Macro screenshot

This way offers a bit more flexibility. For example, it's set up to process the files in the currently open directory, but you could just as easily process files in a selected directory. You could also process the currently selected files. Let me know if any of these options are preferable and I'll adjust it.


Just to point out that this will very much depend on sort order -- and your screen shot is not sorted alphabetically. You'll have to make sure that the Collection used in the For Each action has the same sort option as the Finder window whose items you want to process.


Very good point that I should have made myself. This is why I also included a version based on key simulations as per the original idea.

Thank you so much for helping me out!

The example I gave is just to illustrate what I'm looking for, but in reality, I'm working with audio tracks in an audio software and I sort them manually.

noisneil, your v1 looks amazing and I feel like this would work perfectly in my situation, but for some reason, I can't make it run...I added a hot key trigger and I can run your v2, but your v1 makes my mac produce the error sound, do I need to modify something in your v1?

I wouldn't have thought so, no. Can you use the KM Editor Go to last failed action menu item to narrow down what went wrong?

What DAW are you using?

I'm using Pro Tools. Hmm it looks like it's something to do with the Copy command

So if I click on RUN, the macro runs but I don't see any results as I'm on the KM editor window and not the Finder, and when I press the hot key to run, that doesn't work and I get the error sound...strange because all my hot keys for other macros work...and I tried diff hot keys for this one.

And if I click on the KM Engine and then Trigger Macro by Name, this one doesn't show up, that's probably why I get the error sound

I found the issue!! It's because this macro was in TEST GROUP, and that group was not enable.......it's working great!! Thank you very much!

1 Like