Page 1 of 1

How to Remove Trailing Space or Enclose Year in Parentheses?

PostPosted: Sat Apr 22, 2017 4:57 pm
by chaseholden
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.

Re: How to Remove Trailing Space or Enclose Year in Parenthe

PostPosted: Mon Apr 24, 2017 10:52 am
by Mr_Noodle
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).

Re: How to Remove Trailing Space or Enclose Year in Parenthe

PostPosted: Tue May 16, 2017 9:14 pm
by chaseholden
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.

Re: How to Remove Trailing Space or Enclose Year in Parenthe

PostPosted: Wed May 17, 2017 10:57 am
by Mr_Noodle
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.

Re: How to Remove Trailing Space or Enclose Year in Parenthe

PostPosted: Wed May 17, 2017 9:30 pm
by chaseholden
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.

Re: How to Remove Trailing Space or Enclose Year in Parenthe

PostPosted: Thu May 18, 2017 10:14 am
by Mr_Noodle
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.