How to ignore "lowercased" files?

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

Moderator: Mr_Noodle

How to ignore "lowercased" files? Thu Jan 03, 2013 4:52 am • by DJMurtz
I have a rule that automatically lowercases all downloaded files in ~/Downloads. The rule works, but when "previewing" the rule, it shows that it will apply the same rule again, to already lowercased files.

I searched for a way to implement regular expressions, so I could do something like /[A-Z]+/, but from what I've read, you've implemented your own "regular expressions", which don't support this technique.

Is there any other way to not have the rule be fired over and over again (or maybe only fire a rule on a single file once)? I've changed the rule to only apply to files "created in the last hour", but I'm not sure if this is the correct way to tackle this.
DJMurtz
 
Posts: 12
Joined: Fri Feb 04, 2011 8:34 am

Re: How to ignore "lowercased" files? Thu Jan 03, 2013 12:36 pm • by a_freyer
One method would be to add a "passes shell script" function to test if the filename is lowercase:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     passes shell script (embedded script)

Do the following to the matched file or folder:
     …


Embedded script:

Code: Select all
if [ "$(basename "$1")" == "$(basename "$1" | tr '[A-Z]' '[a-z]')" ] ; then exit 1; else exit 0; fi


Explanation:

IF (the filename without path of the file that Hazel is currently testing) is equal to (that same filename without path in all lowercase)

THEN exit 1 so that Hazel ignores this file: no match because the file name is already lowercase

ELSE exit 0 so that Hazel matches this file: match because the file name is not lowercase
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: How to ignore "lowercased" files? Fri Feb 15, 2013 8:12 pm • by pattulus
That's almost exactly what I tried to do too, so thanks for the solution.

Maybe you could help me to fit the rule for my purpose: I only want to check if the file extension is uppercase.

The base is already working:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     Extension is not blank
         if (all) of the following conditions are met for (the file or folder being processed):
             passes shell script (embedded script)

Do the following to the matched file or folder:
    Rename with Pattern (name)(extension in lowercase)


But when I use your embedded script it checks the whole filename and hence finds more matches then necessary. So I tried to somehow extenend the basename property to only include the extension.

I searched a lot today to find the answer, but apart from crayz attempts like using basename%.* I didn't come close to a solution.

Any help is appreciated.
pattulus
 
Posts: 13
Joined: Sun Nov 06, 2011 1:05 pm

Re: How to ignore "lowercased" files? Sat Feb 16, 2013 2:11 pm • by a_freyer
You could alter the script like this:

Code: Select all
filename=$(basename "$1")
extension="${filename##*.}"
if [ "$extension" == "$(echo "$extension" | tr '[A-Z]' '[a-z]')" ] ; then exit 1; else exit 0; fi


This will match only uppercase extension files.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: How to ignore "lowercased" files? Sat Feb 16, 2013 2:13 pm • by a_freyer
Also you can simplify your rule by removing the nesting:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     Extension is not blank
     passes shell script (embedded script)

Do the following to the matched file or folder:
    Rename with Pattern (name)(extension in lowercase)
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: How to ignore "lowercased" files? Sun Feb 17, 2013 1:47 pm • by pattulus
Great. That works splendid plus I could use this some other rules.
I learned many things this weekend.

Thanks a ton.
pattulus
 
Posts: 13
Joined: Sun Nov 06, 2011 1:05 pm


Return to Support