Replacing Name Mangler

I have played with KM on and off and never really found a use for it. But as I am investigating my workflows and looking for ways to add automation I am thinking this might be it.

I get a folder of audio files from my partner named like so:

Great song_main.wav
Great Song__NO Piano_no Drums.wav
Great Song_30 sec.wav
Great Song 2_main.wav
And so on

I need the files to be renamed to this format:
Great Song.wav
Great Song__NO PIANO_NO DRUMS.wav
Great Song_30 SEC.wav
Great Song 2.wav

So remove "_main" from any titles, and change the rest after the title to ALL CAPS.

I currently use Name Mangler for this with some find/replace and Reg Ex stuff. But Name mangler isn't scriptable, and what I would like to do is add a hazel rule that would watch for the folder and automatically run the naming convention without me having to do it manually.

Is this something KM can handle? If so, I think I just found a reason to buy in. Because I am guessing there are a lot more little things like this that I can do in KM and automate/simplify my workflows.

Thanks!
kc

Hi kc,

This is indeed something KM can handle. Here's an example macro that should get you started. The actions colored with aqua are comments explaining what's happening in each part of the macro:

Auto File Rename.kmmacros (8.4 KB)
image

Results

Before
5
After
05%20PM

All you should need to do is set the path to the folder you want KM to watch at the top of the macro. You shouldn't need to use Hazel at all for this, but if you'd prefer that, there are ways to make KM work with it as well (you can see this thread for an example if you're interested). Good luck, and feel free to ask any follow-up questions.

3 Likes

That’s great. Thanks. Browsing through this forums I’m Starting to wonder if there is anything KM can’t do :grinning:

2 Likes

no -there is nothing
It made my taxes yesterday :sunglasses:
You maybe want to check out the "record-function"
than you can record one renaming process and repeat it as often you like.
I use it all the time for different file-renaming processes...
for example

1 Like

Sorry to be so ignorant about how this all works - perhaps I am starting out with too big a chunk to swallow beginning with this script. But it isn't working. I get the error:

Split Path failed because with path %Variable%LocalFilePath% Macro “Auto File Rename” cancelled (while executing Split Path “%Variable%LocalFilePath%”).

I tried changing some things around by click on various folders to "map" to the script but it didn't work. I created a folder on my Desktop called Test. I am guessing I am missing something I need to change in the Script to work with my setup?

Thanks for your patience and assistance.
Kayle

No problem, Kayle. When you say it's not working, are you trying to run the macro manually? It can be made to work like that, but right now it's designed to work only on files that are newly added to the folder specified at the top. What exactly are you doing that isn't working right now?

Ah - I see. Yes, I was trying to run in manually to see how it worked.

So, I created a new folder on the desktop named Results. I pointed the first action to look at the folder.

I then created some files and added them to that folder. And it worked - but, it seems to be in an endless loop, constantly moving files to the desktop and then putting them back in the folder. Notification center kept counting up to over 1200 notices as it kept going. I eventually threw the folder away to stop the madness.

I copied this from the last couple lines of the log:

NSDestinationFilePath=/Users/doug/Desktop/Test/Body Count.wav, NSFilePath=/Users/doug/Desktop/Body Count.wav, NSUnderlyingError=0x60800005e030 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2018-08-20 19:14:06 Move file /Users/doug/Desktop/Body Count.wav failed with Error Domain=NSCocoaErrorDomain Code=4 "“Body Count.wav” couldn’t be moved to “Test” because either the former doesn’t exist, or the folder containing the latter doesn’t exist." UserInfo={NSSourceFilePathErrorKey=/Users/doug/Desktop/Body Count.wav, NSUserStringVariant=(
Move
), NSDestinationFilePath=/Users/doug/Desktop/Test/Body Count.wav, NSFilePath=/Users/doug/Desktop/Body Count.wav, NSUnderlyingError=0x60800005e030 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} In macro “Auto File Rename” (while executing Move or Rename File “~/Desktop/%Variable%LocalOriginalFileName%”).

So, now that I have it"working" how do I get it to stop, once everything has been renamed? do I have to move them to a different folder in the last step?

Thanks again.
k

I tried setting the last action to a different folder, and it moves the files to that folder, but I get an error on the RegEx stuff. hmmmm. I will await your response.

Cheers

Hi kc,

Sorry for the late response. The endless notifications were caused by the macro being triggered every time the newly renamed files were added to the folder it watches. I'm not sure why it didn't behave that way when I tested it before uploading it, but I can verify that I'm seeing the same problem you did now. As you surmised, the easiest way to fix it is to have the macro move the renamed files to a folder other than the one it watches, so if your workflow can work like that, I would certainly recommend it. Doing so also lets us remove the "Move to Desktop Temporarily" step, which was only in place to workaround an implementation in KM's "move file" action that prevents it from overwriting files with the same name (regardless of capitalization).

As for the regex errors, those weren't important, as they were only telling you that the current file name failed to match the regex pattern used to look for text to capitalize, which is not a big deal since not every file renamed in this macro falls under that pattern. The easiest way around this is to configure those actions to no longer show errors for failing to match that pattern, so that's what I've done in this newer version. Let me know how this one works, and if you run into issues with it as well, please be sure to post the modified macro so I can see what might be going wrong.

Auto File Rename 1.1.kmmacros (7.5 KB)

Thanks so much Gabe. I did try and “reroute” the last step. And it didn’t seem to be working at all with the RegEx error. Nothing was getting moved anywhere or changed. But i haven’t had a chance to really dig in.

I will give your new version a go and see what happens. I will report back.

Thanks again!
Kayle

Just getting back to this one, and this version does indeed work with one caveat - I have to drag the files in one at a time. If I drag in a selection of two or more, I get an error saying:

File action failed because destination already exists

And it lists the folder I am trying to move items to. If I drag them in individually, it works as expected. I have a folder called Staging for the macro to monitor and a folder called Process for it to move the new files to. Another funny thing is in the Process folder, I can see the file name for the audio file, but it is greyed out.

Thanks

That's strange; I tested the macro with multiple files and it worked fine. Can you upload the one you're using so we can see what might be different?

Sure - here is what I did. I don't think I changed anything but the paths - but since I am new, perhaps I did screw it up.

Auto File Rename 1.1.kmmacros (7.6 KB)

Hmm. Assuming that kevin in these file paths is the name of an external drive and not the path to your user folder, nothing seems off at first glance (though I did notice that the target folder is designated as 1 To Process rather than just Process as you said in your earlier post). So if the paths aren't the problem, the next thing to try is a semaphore lock, so that the macro executes in sequence rather than parallel, which should (theoretically at least) prevent any file renaming collisions that might be causing an error like this. Try this version out and see if it makes any difference:

Auto File Rename 1.1.1.kmmacros (7.8 KB)
image

Your assumptions are correct on the folder names. And Kevin is an external hard drive - so the Paths are not the problem. I ran this again, with the same issues. It gives me the same error - "because the destination already exists..."

One additional thing is is doing now though is changing the name in the Staging folder, just not moving it. And I am getting the dimmed file names in the Process folder. So it moves the first one, names the others and fails to move them. One at a time still works as expected.

Cheers!!

04%20PM16%20PM

It would be ok to not move the files at all. I will try and see if I can get it to work without the final move step and just leave them in the Staging folder.

Nope: that didn't work either.

This is very strange; I can't see any reason why the macro would be failing in this way. At this point, the only things I can think to try are:

  1. Trying the macro with folders on your internal drive instead of an external one and seeing if that makes a difference.

  2. Sharing some of the files you're trying to rename here so I can try them with the macro for myself.