Removing character with Rename

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Removing character with Rename Mon Aug 04, 2008 5:58 pm • by wodster
Hi:

I'm just trying to use Hazel to remove the characters "[" and "]" from file names, because those are causing problems. When I create a rule that identifies the characters in a file name, and go on to the rename file step, all I seem to be able to do is add more text to the filename, not remove the problem characters.
wodster
 
Posts: 5
Joined: Mon Aug 04, 2008 5:50 pm

Re: Removing character with Rename Mon Aug 04, 2008 6:09 pm • by Mr_Noodle
You need to use the newly added pattern matching feature for that. I'm not sure where the [] characters are appearing in the filenames but here's an example assuming that the name you want is within the []'s. Note that this is more of an advanced feature.

In the condition, you want to do something like:

If Name matches [(...)]

The (...) is the "Anything" token which you can drag in. What this does is create a pattern which will match a opening square bracket ("[") followed by any sequence of characters ("Anything") followed by a closing square bracket ("]"). Now, this will just match the pattern. What you want is to capture the text that matches the (...). To do this, create a custom token. Drag in the Custom token instead of the Anything token. You will be presented with a new panel where you can specify what text this token "captures". Here, you can drag in the Anything token. Make sure to give the custom token a meaningful name.

Now when you go to the rename action, you will see your new custom token available. Just drag that in where you want the name to go. It will be replaced with whatever text was captured from before.

It may take a bit to wrap your head around it but let me know if you need more help with the above.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Removing character with Rename Mon Aug 04, 2008 6:41 pm • by wodster
Hey Mr. Noodle:

Thanks for writing back, this does seem tricky. I haven't yet found the Anything token to drag in- Is there a way that the New Rule will just recognize the brackets wherever they occur? Some of these file names have more than one occurrence of the brackets, such as "MovieName[2008].AC3[Eng]"
wodster
 
Posts: 5
Joined: Mon Aug 04, 2008 5:50 pm

Re: Removing character with Rename Wed Aug 06, 2008 2:12 pm • by Mr_Noodle
That is a bit trickier.

First off, to get to the pattern interface, make sure you are using "matches". Like "Name matches". Once you click in the field, the interface should expand giving you a bunch of tokens you can drag in.

It's not pretty, but you could provide multiple rules or conditions to handle the cases of one set of square brackets, two sets, etc. Unless you need to handle an arbitrary number of brackets, it should be doable. I say try and get the single case working first (use some test files to make sure you are getting it right). Let me know if you need more assistance.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Removing character with Rename Thu Aug 07, 2008 3:30 am • by wodster
Hi Mr. Noodle:

Well, I followed your instructions as best I could, and I made some good progress, and I am close but not there yet.

Watching the results in the console window is a great help. That way I can see what Hazel is doing.

Right now if I have a file name with brackets in it such as:

"[My[Great]Movie].mov"

Hazel will change the file name to:

"My[Great.mov"

which is something! (It got rid of 3 out of the 4 brackets, but also removed the word "Movie" for some reason. But if the file name is:

"My[Great]Movie.mov"

it won't trigger.

Seems I can only get it to rename the file if the entire filename is enclosed in brackets, is it possible that this is because the "anything" token only appears in the name matches situation, and would need to appear in name contains situation?
wodster
 
Posts: 5
Joined: Mon Aug 04, 2008 5:50 pm

Re: Removing character with Rename Thu Aug 07, 2008 11:17 am • by Mr_Noodle
My example was only for the case of the whole name being enclosed in the brackets. If you want to save the text before and after, you need to add a custom token before and after. In this case, those would also match anything. It would look something like:

"(before bracket)[(inside bracket)](after bracket)"

where each of the things inside parentheses () are custom tokens. Of course, you can name them how you want and the custom tokens should match anything. You will then end up with 3 tokens matching the different parts of the text before, inside and after the brackets.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Removing character with Rename Sat Aug 09, 2008 12:19 am • by wodster
Hi Mr. Noodle:

Thanks for your perseverance

This is one of those "there has to be an easier way!" moments. So I tried using a rename utility (A Better Finder Rename) which does the job in a single step, by replacing the characters "[" and "]" with nothing, so that they just get deleted in a single step, by using a droplet.

So that's not so bad, just requires me to drop any files or folders with the offending bracket characters onto a droplet. But then I thought, maybe Hazel can automate that step, by identifying a file or folder that has a bracket (name contains "[" or "]") but then I couldn't find an appropriate Do The Following command such as "import into" specific app, such as the droplet that A Better Finder Rename creates. Is that Automator or Applescript territory?
wodster
 
Posts: 5
Joined: Mon Aug 04, 2008 5:50 pm

Re: Removing character with Rename Mon Aug 11, 2008 11:09 am • by Mr_Noodle
Yes, I think Automator or Applescript is the way to go here. Someone posted a generic text replace routine in AppleScript here in one of the other threads so you can use that as a base.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Removing character with Rename Tue Aug 12, 2008 5:58 pm • by wodster
Thanks, Mr. Noodle
wodster
 
Posts: 5
Joined: Mon Aug 04, 2008 5:50 pm


Return to Support

cron