Replace Hyphen Character in Filename

Can anyone provide me with a KM action to replace a hyphen (-) character with a space character in a list of files within a folder?

Replace String for Selected Files (or Entire Folder).kmmacros (42.1 KB)

Macro Screenshot

Fantastic!
Do you have the action to download or shall I recreate it?

If you click the blue link, the macro will download.

Also, here's a version that prompts for the character/string to search and the character/string to replace it with.

Replace String for Selected Files (or Entire Folder) - PROMPT.kmmacros (43.3 KB)

Macro Screenshot

1 Like

Maaaaate... that is nothing short of a work of art!

I love KM but it would only be half as good without this amazing community, thank you!

1 Like

No worries bruv. (I can tell from "Maaaaate" that you're a fellow brit!)

In case the title doesn't make it obvious, you can either select one folder or individual files and it will perform the search and replace. If you think you might like to select multiple folders, I can amend the macro to get that working.

I am happy to use it on a folder by folder basis but if you want to tweak it and supply that as a supplemental action I may use it in the future.

One thing to note, pressing the tab key between the Search Character and the Replace Character activated the script and replaced all the hyphens with no spaces at all. Fortunately I was working on a test folder so no harm done otherwise I may have to click each file name and add the spaces back in! I wonder if you can force the user to add a Replace Character so that this cannot be left blank.

David

PS. Yes I am a Brit, I live just outside Tonbridge in Kent.

You mean while entering info into the Prompt fields? That shouldn't happen unless you hit Enter. I'll have a look at a safety feature nonetheless.

Just a thought - renaming, renumbering, etc multiple files in the Finder is such a common and recurring task that I feel it is one thing it’s worth having a dedicated small app for. Apart from anything, for the extra safety and checks you get.

I love Keyboard Maestro but for renaming lots of files, I would use a dedicated app. I’ve been using A Better Finder Rename for years and I know others here recommend Name Mangler.

I think they are also in the Mac App Store.

1 Like

Same here. In fact, for something as simple as replacing a character/string, you can just use the Finder's rename function (right-click context menu).

For the sake of it, here's a version that works for multiple folders and asks for confirmation before removing (i.e. replacing with nothing) a character or string, as requested.

Maybe try it on a few test folders though, in case you accidentally trigger the macro prematurely again. I'm still not sure why tabbing would have triggered the macro. Never seen that before.

Replace String for Selected Files (or Entire Folder) - PROMPT.kmmacros (46.4 KB)

Macro Screenshot

Thanks Neil, it's working great, very odd that the tab key triggers the OK button, I've never seen that before either - maybe somebody else can answer that question?

Is it possible to remove the error notifications that pop up if some of the filenames in the selection (or folder) do not have the search character?

Yeah, just get rid of this tick.

Sure you don't have a macro that simulates Enter when you hit Tab? That's the only reason I can think of. Maybe try the debugger, hit Tab and see what KM's up to.