Delete Everything Within Brackets [ ] and Brackets Themselves

Hello, I usually create audio files with Ableton Live and these files, when exported, get an extra text append in the name with the time the file was created. This can be useful for some, but annoying for others. I am amongst the ones who don't really need this. So I always have to delete this append text.
I was looking for a way to delete everything within brackets [ ] and brackets themselves by the press of a button.
I thing it could be something easily covered with RegEx, but no matter I tried, I have no clue.
Anyone could help?
Paolo

example file [2022-12-08 214904]

Assuming you are selecting files in the Finder, you can remove the extra text you have shown, without using Regex. The below example will work whether you select one file or multiple files.

(Test this on a copy of the files to make sure it does what you want before trying it on real work files!)

Click to Show Image of Macro

EXAMPLE Remove Text in Brackets.kmmacros (3.3 KB)

EXAMPLE Remove Text in Brackets

This makes use of a feature Keyboard Maestro has to split Variables into parts separated by a defined delimiter. In this case the delimiter is " [" as that is the first unique part of the text you want to remove.

If you have a look at the lower section of this page of the manual this concept of splitting variables is explained in detail.

So, we take the first part of the path and name up to " [" and add on the file extension to make a new path, name and extension for the rename of each file.

1 Like

Thank you very much! It works perfectly. Fantastic.

I have a problem, though. I use an app called Path Finder that replaces Finder, so the macro will not work with it.

Any workaround?

Provided you can tell Keyboard Maestro the path to the folder that contains the files you should be able to use the same logic. However, this would look at every file in the folder for the pattern rather than selected files which might not be a problem. Personally, I would just use the Finder for this task and select the files to rename.

Or... actually I probably wouldn't use Keyboard Maestro at all. I would use a dedicated file renaming App like Name Mangler or A Better Finder Rename. Renaming files is such a common task that it's better and safer to have a dedicated app rather than having to write Macros each time.

2 Likes

Thank you very much, you gave me all the infos I needed and more. Much appreciated.

1 Like

See this topic:

Automating Path Finder

Thank you, I'll dive into it