How to Remove Trailing Space or Enclose Year in Parentheses?

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

Moderator: Mr_Noodle

I need Hazel to do two things:
1. remove trailing space in a filename if one exists, excluding extension. (1968) .jpg ==> (1968).jpg
2. enclose any 4 digit year within parentheses 1969 ==> (1969)

I've read through the help files backwards and forwards and I cannot figure this out, still.
Does anybody have any suggestion how to accomplish this? My attempts all fail.
I have it successfully replacing text in many ways and I could do it with grep, but just not in Hazel.
chaseholden
 
Posts: 9
Joined: Wed Oct 12, 2016 1:18 pm

Look up "match patterns" in the help. Grab the part of the name you care about into a custom attribute, then use that in the Rename, adding the parts you want (like parens), while leaving out the parts you don't (the trailing spaces).
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I've spent several hours trying to experiment with deleting a trailing space before the file extension but to no avail.

Your Rule Match Preview is no help because it shows a green checkmark for a match, but clicking check reveals two identical name/filenames excluding the file suffix/extension. Because file extensions are not displayed and spaces are invisible, trailing space removal is impossible to determine here.

Nonetheless, I created a Name Matches "• Custom Text" pattern match for [...] anything called "[•Filename] " <= notice space after [] so that Hazel will match the pattern of any text whatsoever followed by a space, matching the 1st occurrence from the end.
This matches several files found confirmed with green checkmark.

Rename with pattern: [•Filename][extension] is selected, notice space is omitted this time.

However, the filenames never change, retaining the unwanted trailing space in filenames.
chaseholden
 
Posts: 9
Joined: Wed Oct 12, 2016 1:18 pm

If the space is before the extension, then you can check for a space at the end of "Name". If you want the extension in there, then use "Full name" instead. Try something like this:
Code: Select all
    Name matches (• file name)


There's a space at the end of that pattern. When it matches, •file name will have the name minus the trailing space so re-use that in a rename pattern.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thank you, Mr. Noodle! Success.
FWIW, even though the match was on "Name" rather than "Full Name," I had to rename with [•Filename][extension]
This was not intuitive since there was no [extension] pattern match in the Find Condition.
chaseholden
 
Posts: 9
Joined: Wed Oct 12, 2016 1:18 pm

It's consistent. "Name" is the part of the file before the extension and is used the same way both in conditions and in the Rename action. •file name is something you defined yourself. You could have named it "barglyworf" and it would have worked the same way.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support