"Sine qua non condition" for rules to apply

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

Moderator: Mr_Noodle

Hi all!

I'm all new to Hazel and mostly to automation in general. I've read trough most of the manual and looked at some relevant posts without any success in finding an applicable condition/rule.
I've got a watched folder were I'll be downloading three files into every time it's in use. The files will always be an .epub, a mobi & a .zip file. The pdf within the zip file contains the file name that will later be distributed to the .epub & .mobi file. Once this is done the files will be distributed to their specific folder.
With the help of gglick over at the KM forum I got a perfect macro for the distribution of the file name. Combining this with a Hazel rule to firstly unarchive the zip-file before the script runs and later moving the three correctly named files to the desired folder with Hazel was no problem.
Since I don't always want to have to think about in what order I download the mentioned files I'm looking for a "sine qua non condition" at the top that will prevent further rule matching until the watched folder contains all three files mentioned. Without that and if downloading the zip-file first or second my "name giving file" will have been processed and my .epub & .mobi will remain "unnamed" and therefore not get moved.

Any help/guidance would be much appreciated!
Last edited by Sokrates1966 on Thu Sep 09, 2021 1:14 pm, edited 1 time in total.
Sokrates1966
 
Posts: 2
Joined: Tue Sep 07, 2021 7:50 pm

Check "nested conditions" in the manual. You can set up a nested condition to match a file based on other files in the same folder. Example:
Code: Select all
If (all) match
    Name matches (• file name)
    Extension is zip
    If (all) match for (any file in the same folder)
        Name matches (• file name)
        Extension is epub
    If (all) match for (any file in the same folder)
        Name matches (• file name)
        Extension is mobi

The above will match a zip file if there is an epub and mobi file with the same name in the same folder. You may need to play around with it but that gives the basic gist.
Mr_Noodle
Site Admin
 
Posts: 9717
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Wauw! Thanks so much Mr. Noodle!

A great teaching point for me!

I did read through the "nested conditions" beforehand but maybe not thoroughly enough or I just didn't catch it for my user case (or grasp it :wink:). I've adopted it to my use by leaving out the "nested name condition" and it's working like a charm:

Code: Select all
If (all) match
    Extension is zip
    If (all) match for (any file in the same folder)
       Extension is epub
    If (all) match for (any file in the same folder)
        Extension is mobi


Is my assumption correct that the "nested name condition" is not necessary for my specific case but would need to be used if I'd be using a more general folder like "Downloads"? Or just to assure that the matching will not apply to "any" other files accidentally dropped into my specially created folder?

What I'm unsure of is the "• file name". Is that the dot for "custom text" from within the selection filed of the match name condition?
Sokrates1966
 
Posts: 2
Joined: Tue Sep 07, 2021 7:50 pm

That is a custom text attribute. Forgot to mention this before but look up the chapter on match patterns. You want that to be set to match "anything". What happens is that it will grab the name of the file. Subsequent uses of that text attribute will require that it match what was matched earlier. That's how you check that the files have the same name.
Mr_Noodle
Site Admin
 
Posts: 9717
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron