Macro to rename folder and files within the folder

Hi I’m new to KM and struggling with setting up what I think is a complex macro. I’m hoping someone out there will be able to help

I’m using an iMac with Sierra OS

Imagine that you have a folder with a Word file named John Smith within it. Also in this folder is another folder called template folder.

Within the template folder are seven word files called generic 1 generic 2 generic 3 generic 4 generic 5 generic 6 generic and generic 7.

What I would like to do is that whilst my cursor is placed on the John Smith file, I would like to copy the name John Smith and move up to the template folder and rename this folder as John Smith.

I would then like to open up the newly renamed John Smith folder and place the name John Smith in front of all the seven Word documents within this folder so that it reads john smith generic 1, john smith generic 2 etc and then move back to the previous location from where I started

Is there anyone that can help me with this because I use this task repetitively and spend a lot of time renaming the folders and files

Thank you so much and are waiting in anticipation

First let’s see if I got your folder structure correctly.

The macro will work for a given folder structure like this:

The output will be this:

  1. Set the correct name of your template folder in the green action
  2. Select your initial file (“John Smith.docx” in the example) in the Finder
  3. Run the macro

Please note: The macro does not do error checks. However if no folder with the name of the template folder is found, it won’t go far (I hope). Anyway, treat this macro as a draft!

_[draft] Renaming Fun.kmmacros (4.3 KB)

Hi Tom

Thank you for a prompt response. The file structure looks fine.

Is there anyway I can import the macro you have presented directly into my KM or will I have to copy yours ?



Is there anyway I can import the macro

My post above contains a link (at the bottom of the post).

  1. Click the link to download the macro file
  2. Go to your Downloads folder and double-click the downloaded macro file → it will install automatically in KM Editor
  3. Assign your preferred hotkey and run the macro (see instructions in my post)

Thank you very much

I will try this so and update you


Dr. L. Hawa

Hi Tom

I have followed instructions but it does not seem to work. I am sure it a silly error on my part.

I have attached screen shots of the actual folder called Manchester with the subdirectory of 0 New Folder and John smith. I have also sent you a screen shot of the amended macro where you have asked me to make the changes.

Please let me know what I have done incorrectly



Dr. L. Hawa

Yes, it seems to be just a little error:

In the variable definition (green action) you must set the value of the variable to the actual name of your templates folder.

You have changed both the name and the value of the variable. But the name must remain as it is because the other actions work with that variable.

So, if the name of your templates folder is “0 New Folder”, the variable definition should look like this:

Hi Tom

You are my absolute hero !
Thank you so much.
May I tax your enormous skill with a further challenge.

Imagine the same set up but instead of having just one file called John Smith, I have say 15 different files all with different names like Peter Pan Joan Ellis Jackie conran etc.
What I used to do before is if I knew I had 15 such files I would make 15 copies of the 0 New folder and they would then be sequentially names 0 new folder copy1, 0 new folder copy 2 etc all the way up to 0 new folder 15.

If I run the current running macro it will work with 0 new folder and rename it John smith. But for me to do the same for the other 14 files, I would have to rename 0 new folder copy one to 0 new folder before I can execute the macro again and then have to do this for the other 13 files. Very time consuming and boring.

Is there a way of tweaking your current working macro so that when we execute it say with file John smith then firstly it automatically duplicates the 0 new folder thereby creating one called 0 new copy 1. It then renames the 0 new copy 1 as John smith a then the seven files within the folder like it does now. That way when we complete the macro we are left with the original 0 new folder and so I can go to the next file say Peter Pan and simply run the macro again.

Can you help please

If I understood you correctly, this should do the trick:

_[draft] Renaming Fun Mk II (with alert).kmmacros (8.5 KB)

Edit (2017-02-07 22:52 Z):

Replaced with a new version that throws an alert and cancels the macro if a folder with the same name already exists.

This is brilliant

Thank You


Dr. L. Hawa

Hi Again

Switching from PC to Apple is pleasurable and painful. One thing I am so frustrated about is that there is no single key equivalent to the PC delete key (i.e. forward delete). I know that you can use Fn and backspace but there must be a way of using say the eject button (the key on the top right hand side of the keyboard) as the delete key

Any ideas


If you use a full keyboard, as opposed to a laptop keyboard, you can use the "forward delete key", usually in the center section of keys.

Of course you could always use a KM Macro to map a function key to forward delete.

But that would still mean that we use two keys for the backspace function.

Is there anyway that you can map the eject key only as backspace ?


No, that is not correct.
You would just press "F12" (for example), and the macro would simulate the forward delete keystroke.

I don't think so using KM. But there may be other tools that would allow you to do this.

Maybe you are not aware that the Media Eject key (:eject_button:) is tremendously useful:

Key combo Function
Eject media
⌃⏏ Sleep/Restart/Shutdown dialog
⌥⌘⏏ Sleep
⌃⌘⏏ Restart
⌃⌥⌘⏏ Shutdown
⌃⇧⏏ Display sleep
‌ To make the Eject Media functionality more useful, you can try [this macro]( It shows you a list of all mounted disks and lets you select which one to eject.
1 Like

Thank you Tom

Clearly not aware of many things. However it would still be nice to have a single key that can operate as a backspace.

Best wishes


To be clear, you have that: The primary "delete" key IS the backspace key.

I know you really want a single key for "forward delete", but I don't think that is going to happen unless you use a Function Key (like "F12"). To be honest, just try using the "fn" key + "delete" for a while. I think you will find it will soon become muscle memory. :wink:

Here are some guides that might help your journey from Windows to Mac:

Thank You

2 posts were split to a new topic: How Do I Print Multiple PDF Pages on One Physical Page?

Even Better