Batch Rename: Space Deletions

Hi, I'm looking for a macro that will allow me to change a batch of filenames, with the only change being the elimination of word spaces from the names. I'm not very adept at this sort of thing, and am hoping to find some guidance here.

By a "batch of filenames", do you mean a plain text list of names (saved in a file, or in the clipboard, or in a variable...), a Finder selection, folder contents, or something else?

The Wiki pages about Collections and for each will probably be relevant.

The search and replace action would probably meet your needs.

That's most of us. :slightly_smiling_face: I hope I have given you some pointers but you might be better off using a file name utility such as Name Mangler or, if you want such renaming to run automatically, Hazel.

And run backups before trying anything, won't you. :wink:

Hidden away in Rename Files Mystery are two versions of a rename macro that sounds fancy but works simply too. (Search for 'Perl' to find the one I use.)

Simple search for a space and replace it with nothing.

Sorry, I should have clarified that I meant filenames in Finder.

The Rename Files Mystery macro might be what I need, but I'm not sure where to make the substitutions you mean.

When you run the macro it prompts for them. It provides the change so you can bale out if you make a mistake.

Thanks so much, I'll give it a shot. From a backup folder, of course. :smiley:

Oy, pardon my ignorance but I don't see how I run this macro.

Download it from the link in that discussion. Double click to install it. Set a hot key you like. Select a set of files in the Finder. Follow the prompts.

For example, I'm renaming test.html to js-zoom.html here:

In your case, though, you won't see anything in the first dialog because you're looking for a space and replacing it with nothing. But you'll see the consequences in the preview that follows.

Instead of activating the macro successfully, all that's happening is that Finder selects the first file in the folder -- which wasn't one of the files I'd selected for renaming.

I've tried several different hotkeys, but getting the same result with each of them. Any idea what could be going wrong?

Is the Macro group activate for the Finder? You might try the Interactive Help on the Keyboard Maestro editor's Help menu to see what's going on. Or look in the logs on that same menu.

That did it! I was totally unaware of the Interactive Help feature, and it did indeed locate that the macro was not activated. It is now activating away actively.

I'm very happy with it and this isn't a complaint, but you might like to know that rather than locating and deleting all word spaces in each filename, the macro is locating and deleting the first word space in each name. That's hardly a problem though, as I can just run it repeatedly until the longest name is finally completed.

Thanks very much for your patient help.

No, if you just type a single space in the Search box, it should target any space in the file name. I just tried it on a test file and it worked as expected.

There are multiple spaces in the original of this:

It is possible to do the same thing in Finder, selecting the files and then choosing the option Rename, from menu File or from contextual menu.

For deleting a space, yes, but unlike the Finder this macro supports regular expressions. So the Find could be \s for any whitespace (space, tab, etc.) in the macro.

I agree, my answer was for the simple question of the spaces in file names.

1 Like