Noob - How To Rename Batch of files in a specific manner

Hi, I've searched through renaming and it's all rather complicated normally requiring user input etc. Could anyone point me in the right direction for doing the following:

I have audio files that are named with a _01 to _13 at the end of each name
This relates to the chromatic scale in music (they are sample) so
So - _01 should be _C
_02 should be _C#
_03 should be _D
etc etc

Can anyone help me please?

Kind regards

There are two solutions that enable batch renaming of selected Finder files:

  • Batch Rename Files in the Finder, which you can also find in your Keyboard Maestro Macro Library

  • Either of the two revisions of that macro at the end of Rename Files Mystery (although the Perl version has worked better than the JavaScript version for me). These enable regular expressions (which you don't need in this case).

Do something like:

This assumes _01 etc do not appear anywhere else in the path of the file (including parent folders).

Make sure you have a full Mac backup, and a backup of the specific folder, before testing such a macro.

Hi @Skipstream, you might want to take a look at this discussion Deleting from a file name where I very recently posted a macro that is virtually the same as outlined in @peternlewis' steps above.

You would need to edit the search and replace regex strings in my macro as per Peter's instructions but that shouldn't be too hard for you to try.

Good luck!

1 Like

Hello @tiffle , thank you for you for the suggestion and macros download.

I replaced sections, but I've yet to have have successfully run the execution command.

The goal is to highlight folder names (not files) and utilize the hot key 'command V' to paste their names elsewhere. It is seemingly simple, yet, perhaps I've overlooked a detail in this macros.

Where multiple folders are already named, I'd like to paste their names ontop of other folders. How might this be done?

Thank you,

Good question! If only I understood what it is that you are trying to achieve. The macro you've posted is very confusing as you have a loop (for...each) that does nothing with the loop variable (VarName).

Can you describe the steps please that you'd do manually so I can get a better idea. Something like:

1 Select some folders in Finder
2 etc.

Or even provide two screenshots showing the before and after situations.


Hello @tiffle thank you for your response.

Here you can see a set of folders all titled individually. On the right hand side you can see untitled folders needing the exact names from the highlighted left hand selection. The goal is to batch rename the folders on the right with the names from the left hand side.

If it were possible to create empty folders with the former names, then perhaps this execution would be better compared to running a batch copy and paste (rename) functionality. But the key is that only the names are copied and not the contents within the folders.

Presuming that copying Finder's clipboard for names is simpler than batch creating folders with identical titles, the steps would be as follows:

  1. Select folders
  2. Copy folders (just their names so... command c?)
  3. Go to the desired location
  4. Paste (again, only names and not the contents)

Thank you for this macros tweak that indeed speeds up workflow!

That's actually a bad assumption :slight_smile: ... doing a batch creation with identical titles is a three-action macro. Action one is For Each, then inside that, an action that extracts a folder name, and another that creates a new folder. Here's a demo:

Download Macro(s): foreach finder naming.kmmacros (2.4 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.4.1
  • Keyboard Maestro v11.0.2

Note that you'll need to edit the last action to specify the destination, and that this is just a stub of a macro: There's no error checking, you probably want to specify folders differently, etc. But it works: Create a new empty folder, put the path to that empty folder in the last action, select a bunch of folders in Finder, then launch the macro. When it's done (quite quickly), the new folder will have empty folders matching the names of those in the selection.


1 Like

As @griffman said - that's an incorrect assumption.

Here's my example macro to do the job. It's similar to @griffman's but it ensures only folders are processed (so if you've selected some files they are ignored) and you need to set the target folder in the red action. As an exercise, you could replace this with a Prompt for User Input or similar action to specify the target folder.

Download Macro(s): Test Recreate Folders.kmmacros (3.4 KB)


  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.6.1
  • Keyboard Maestro v11.0.2

I hope that's helpful.

1 Like

This would be a much better way of doing things.

The following will create (1st level only) folders in a folder of your choosing, corresponding to the current Finder selection:

Make Folders from Finder Selection.kmmacros (2.0 KB)


It's rather simplistic, with no error checking in case eg you've selected files as well, but it's easily tweaked and should give you a good starting point to make it your own.

Edit: Beaten to the punch by the gurus -- again! But I think I win the "least actions used" prize :wink:

1 Like

So when's the first annual Obfuscated KM Macros competition anyway? :wink:


Insta-win for the JXA gurus, IMO...

That'd have to be an exclusionary qualifying rule: No JavaScript, AppleScript, or Shell Script actions :). Probably also have to exclude Custom HTML Prompts.

Because otherwise I completely agree—we'd be handing the trophy to @ComplexPoint today!


1 Like

Anything seems foreign before you learn it :slight_smile:

1 Like

I would love to learn JavaScript in more detail, and it's on my list. But I never manage to quite make the time for it, and even if I do, my "old dog" brain has troubles grasping most of it.

I love the stuff you post, but only understand about 5% of it. It's incredible what it can do, though.


JSON is more than half of it. The rest is functions. Go and practice them :slight_smile:

The rest is functions

Three flavours:

  1. Simple lambdas
const doubled = x => 2 * x;

return doubled(7);
// → 14
  1. Light functions with their own name-space, for defining local names. (i.e. simple functions with curly brackets)
const circumference = r => {
    const c = 2 * Math.PI;

    return c * r;
  1. Generator functions, with the function keyword trailing an asterisk
(() => {
    "use strict";

    // repeat :: a -> Generator [a]
    const repeat = function* (x) {
        while (true) {
            yield x;

    // take :: Int -> Gen [a] -> [a]
    const take = n =>
        // The first n elements of a non-finite list.
        xs => Array.from(
            {length: n},
            () => {
                const x =;

                return x.done
                    ? []
                    : [x.value];

    return take(5)(
    .join(" ");

We used to need the old heavy-weight function keyword in cases where access to an arguments vector was useful.

Now we can use the three dot spread operator when a definition needs to to refer to a list of arguments:

Expand disclosure triangle to view JS source
(() => {
    "use strict";

    // PHI – Golden Ratio

    const main = () =>

    // --------------------- GENERIC ---------------------

    // compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
    const compose = (...fs) =>
        // A function defined by the right-to-left
        // composition of all the functions in fs.
            (f, g) => x => f(g(x)),
            x => x

    const half = x => x / 2;

    const pred = x =>
        x - 1;

    const sqrt = n =>
        0 <= n
            ? Math.sqrt(n)
            : undefined;

    const succ = x =>
        1 + x;

    // MAIN ---
    return main();
1 Like

Damn -- that's where I've been going wrong...

Reset and try again.

: ) The dance steps are here:

LAMBDA: The ultimate Excel worksheet function - Microsoft Research

1 Like

This topic has not been handled well.

The question by amory should probably have been a new topic which would aid in getting a better result.

After that, the digression on to a discussion of macro styles and lambdas has completely confused the topic making it very hard for Amory to actually get an understanding of the macro. I'd clean it up, but it doesn't have a clear topic to go to. But please consider the best way to handle digressions before wandering off in to the weeds, no matter how interesting those digressions might be.

Amory - if you want to batch create folders with a set of names (from another selected folder), then you can do that more easily than batch renaming existing folders. Do your “untitled folder copy N” folders have contents in them already, or are they intended to be empty?

If they are intended to be created empty, then my approach would be to:

  • Select the desired source folder names, and then trigger the macro.
  • The macro:
    • Saves the FinderSelections token value to get the list of folder names.
    • Puts up an Alert asking you to select the destination folder.
    • Use either the FinderSelection token or the FinderInsertionLocation token to determine the target location.
    • uses a For Each action with the Lines In collection to iterate through the saved list.
    • uses the Split Path action to get the name of the folder
    • uses the New Folder action to create a new folder with that name at the target location.