Move Folders in the Finder to a New Location and Rename Them Using the Parent's Parent Directory Name

Hi Everyone!

I have been pouring over every piece of documentation about clipboards and manipulating the values in clipboard data (either system or named). I've come across regular expressions and the documentation was confusing to me. I'm self-taught programming, but I know I have a long way to go.

My goal is to copy a path of a folder (using command + alt + c) and then change the content of the clipboard to a portion of the path (mostly the end). Then I want it to rename the file using the new string. I have tried and discarded many things and I don't remember a lot of it (been working on it for like five hours, I'm nothing if not persistent), but I will most likely remember what I have and haven't tried.

I believe I need to use regular expressions (Regular Expressions [Keyboard Maestro Wiki]) to search the string, but the search modifiers are very confusing to me.

Here's what I currently have set to trigger when I hold down F10:

I'm hoping that I'm on the right track, but this particular task feels like I'm making it way more complicated than it needs to be. If anyone has some guidance or is willing to work with me a little so I can learn, I would greatly appreciate it!

Thank you so much!

There’s an easier way to extract parts from a file path and that’s by using action:Split Path [Keyboard Maestro Wiki]

It’s much easier to use than regexes.

Hey Colin,

Yes, you're making this far more difficult than it needs to be.

Please provide real-world examples of the file name you want to change, and the name you want to change it to.

Once we have that it'll be simple.

-Chris

This looks to be exactly what I need. Not sure why I didn't see it to begin with. I think I was too focused on the clipboard aspect. Thank you for pointing me in the right direction!

So it looks like tiffle pointed me in the right direction, but after playing with it for a little while I still don't quite understand.

So I'm looking to change the name of the folder, not a specific file, but I suspect that's irrelevant.

Here are some examples:

~/Downloads/Flat icons Vol. 1/PNG/512
~/Downloads/Flat icons Vol. 1/PNG/256
~/Downloads/Flat icons Vol. 1/PNG/128

I'm looking to get rid of everything that ~ stands in for as well as "Downloads" and then use the rest to replace the number at the end with everything leftover.

Thank you for such a quick reply and your willingness to help is much appreciated!

Okay, but that's not what you said before:

Thus my confusion.

~/Downloads/Flat icons Vol. 1/PNG/128

This is not definitively a folder, and it's helpful to know for sure what we're dealing with.

This would definitively be a folder – given the trailing slash.

~/Downloads/Flat icons Vol. 1/PNG/128/

Unix convention tends to leave off the trailing slash, but I think that's remarkably stupid due to the ambiguity.

That's not a before and after example. Verbal explanations are often unclear.

Your workflow is to what?

  • Select a folder.
  • Hit a hotkey.
  • Transform the name of the last folder in the path?
    • To exactly what?

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?

-Chris

1 Like

Hey Colin,

Okay, here's your basic task – but I can't finish the macro without the requested information.

Run it on an item selected in the Finder, and you'll get a pop-up window with some information. The rename action is disabled.

-Chris


Rename the Selected Finder Item v1.00.kmmacros (11 KB)

Macro-Image

Keyboard Maestro Export

I apologize for the confusion, I see now that I wasn't specific enough and that’s on me. I’m also sorry for not getting back to you sooner. I was trying to make it as detailed and concise as possible.

Version of KM: 10.0

Version of macOS: 12.0.1

Workflow and goal: I want to take a selected folder's path and use it to rename the folder to something simple. Then I want to move the newly named folder to a more accessible destination saving myself the headache of navigating to the proper folder each time. From there I will manually import the folder into an app designed to organize my collection of icons (IconJar). I will have to do this workflow hundreds of times (there’s somewhere around 40,000 icons) and I'm hoping this will speed it up considerably.

Example:

I want this:

/Users/twicedouble/Downloads/Flat icons Vol. 1/PNG/128/

To change to this:

Flat icons Vol. 1

And then move it here:

/Users/twicedouble/Desktop/Icons/

Here's what I had before. I suspect it won't be of much use but just in case:

Split Path Action (v10.0)

Split Path.kmactions (390 B)

Keyboard Maestro Export

I am so sorry I didn’t communicate all of this better and I really appreciate your help and your patience.

That is exactly what I was looking for!

Does that given you enough to move forward?

Or do you need more help?

image

I think I messed up when I specified the move location:

Quite.

I goofed up the Parsed Text, because I failed to provide a new variable for it – so the parsed text replaced the full path.

Try v1.0.1.

-Chris


Rename the Selected Finder Item v1.01.kmmacros (13 KB)

Macro-Image

Keyboard Maestro Export

Everything's working! Thank you so much, Chris. You're the best.

1 Like