Rename Folders with names from "FirstName(s) LastName" to "LastName, Firstname(s)

Hello everybody,
I have been struggling with this for a long time and I can't make it work.

I have a list of author folders which are basically "Franz Kafka" and "Johann Wolfgang von Goethe". The Last Word is always the last name (there will be exceptions, but those I can deal with manually).

What I need is a macro that copies the last word of the folder (e.g. Kafka or Goethe) to the very front of of the folder's name, insert it and insert a comma.

It should look like this:
Franz Kafka > Kafka, Franz
Johann Wolfgang von Goethe > Goethe, Johann Wolfgang von

Does anybody have a solution for this problem? I know this is an extremely resourceful forum, so I keep my hopes up. Thanks for your help in advance.
Alex.

Permit me to ask for a clarification. Why don't you consider "von" part of the surname? In most social and legal forums, the "von" is part of the surname. But I guess it's easier to solve if you don't consider it part of the surname.

I found a page on the web where this question was asked and answered (without using KM), however it may only work when there is a single given name and a single surname. I'm not sure. It's probably a good page to check, regardless.

1 Like

Indeed, it is easier to program. That‘s my reason. :slight_smile:

However, in German, "von" as in "Johann Wolfgang von Goethe" is not considered part of the last name. "Von" is a nobiliary particle that indicates nobility or geographical origin. Therefore, the last name is "Goethe," and "von" is a separate part that signifies noble status or origin.

Thanks for the automator! I‘ll try it, most appreciated. :slight_smile:

No need for Automator if you don't want it—you can do it with a fairly simple macro. Source data:

image

After macro run:

image

The macro is just a few steps:

Download Macro(s): folder renamer.kmmacros (3.0 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.5
  • Keyboard Maestro v11.0.3

Note that there is zero error checking or feedback here—I don't check that only folders are selected, I don't confirm that each file was successfully renamed, there's no onscreen notice of successful renaming, etc. I would recommend doing at least some of that stuff, depending on how you're using the macro. But it does work.

-rob.

1 Like

Thank you so much! I will try it! :+1:
This works incredibly well! Thank you!!!

I have just one question, I don‘t understand what it does, when the folder exists already.

Let‘s say there is
„Mike Folder“ which I choose to rename
and there is already the folder „Folder, Mike“.

What seems to happen is that it puts the content of „Mike Folder“, i.e. the folder into „Folder, Mike“. However, I don‘t find this as a possible behaviour in the macro.

Folder, Mike

Mike Folder

In another instance, which I can‘t reproduce right now, it refused to work (which would make sense).

Thanks for your amazing help!

I think this is due to how the Rename/Move action works in Keyboard Maestro: If the destination is a folder, and the source is a folder, then the contents are moved from the old folder to the new folder. So that condition is true for an existing folder.

The attached version adds a test to make sure the folder doesn't exist; if it does, it tells you it can't rename the affected folder and skips it.

Download Macro(s): folder renamer.kmmacros (5.6 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.5
  • Keyboard Maestro v11.0.3

I'm sure there are folder names that will trip up the macro: Single-word folders, for instance, will be reported as already existing. But as noted, the template I created had no error checking and assumed everything matched the format you described. The above version now has at least one level of error checking.

-rob.

2 Likes

Wow, Rob, you are nothing short than amazing. Absolutely brillant!

This is so helpful and will save me soooooo much time.
Thanks for all your amazing work.
Have a wonderful day!

Alex

1 Like