Page 1 of 1

"Sine qua non condition" for rules to apply

PostPosted: Wed Sep 08, 2021 11:57 am
by Sokrates1966
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!

Re: "Sine qua non condition" for rules to apply

PostPosted: Thu Sep 09, 2021 8:54 am
by Mr_Noodle
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.

Re: "Sine qua non condition" for rules to apply

PostPosted: Thu Sep 09, 2021 1:08 pm
by Sokrates1966
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?

Re: "Sine qua non condition" for rules to apply

PostPosted: Fri Sep 10, 2021 9:54 am
by Mr_Noodle
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.