Rename from list [SOLVED]

This is something I've always missed in KM and, unless I'm missing something, would love to have as an option.

I have a list of files and a list of name. I want to rename those files based on that list. So files:
file-sjjdk1.wav
file-aoijf.wav
file-244.wav

and a list of name
drums
bass
piano

so I want to cycle through each list and rename them and in the end I would have the files:
drums.wav
bass.wav
piano.wav

The For Each cycles through each file, but how can I say that on each loop it increases 1 line in the list? I know I can use indexes for lists separated with commas, but how about lines?

I was reading this:
https://wiki.keyboardmaestro.com/manual/Variables

and it mentions custom delimiters, but for new lines, how does that work?


EDIT: Found it. I just need to add the regex /n for a new line. So if my variables is Local__list, then to target line #3 I would use:
%Variable%Local__list[3]\n%

Awesome!!! :slight_smile:

You might get some help from this thread:

1 Like

I just updated my original post at the end.
I was looking for the regex \n like this
%Variable%Local__list[i]\n%

This is something I need here and there for different scenarios and I thought it wasn't possible to target specific lines.

I will check the post you shared as well.

You'll be surprised at how useful it is! :grinning:

1 Like

Yeah, I have some other old macros where I had to rely on additional actions to convert a list to an array using comma as delimiter (because I thought it was the only option), but now I can update them. Especially when the original line contains a comma as part of the "name" and so I would have to convert that comma into something else to avoid conflicts with the delimiter, then convert it back.
Always great to learn these things once in a while :slight_smile:

1 Like

This is a Token, not a regex -- but the non-printing character Tokens are a bit different to the ones you're used to (eg %ApplicationName%1%) in that they aren't enclosed in %s.

See the relevant section of the manual for more.