Page 1 of 1

Another subfolder question

PostPosted: Sun Jul 08, 2012 7:15 pm
by JackJames
Hi,

I have another subfolder question. Apologies if it's something obvious, I've been through the examples but there's still something I'm missing.

I'm trying to make a file structure which is colour labelled based on whether a folder is empty or not.

So far I can get some of it to work, but not all - perhaps you could help me with the last bit.

Using another program, we make a file structure for a new project based on a template, and this contains a number of folders which are empty (though some contain empty subfolders) - and are labelled grey. What I want Hazel to do is clear the label if someone puts something into the folder. I can make that work easily with one folder, but when subfolders are involved I struggle.

So far I have a test folder structure that looks like this:

Deliverables/Final/Compressions/WMV/
All labelled grey, and except for the subfolders, empty.

And a set of rules like this:

Rule 1 'Look inside sub-folders'
Code: Select all
If all of the following conditions are met for any of it's sub-files or folders
Kind is folder
Do the following to the matched file or folder
Run rules on contents


Rule 2 'Remove colour label from folders with contents (there must be a better way to do this not using size?)
Code: Select all
If all of the following conditions are met for any of it's sub-files or folders
Color label is Gray
Size is greater than 15KB
Do the following to the matched file or folder
Set color label to clear



Rule 3 'If this folder contains a subfolder not labelled grey, label the parent folder grey too' (this isn't working because I've misunderstood how it works, I think?)
Code: Select all
If any of the following conditions are met for any of it's sub-files or folders
Color label is not Gray
Do the following to the matched file or folder
Set color label to clear



If I put a WMV file into the WMV folder, Hazel removes the colour label from the the WMV folder as it should, but I also need it to remove the label from the parent folders all the way up the chain.

What have I got wrong here? Looking in the preview mode, it seems like rule 3 is asking Hazel to set the colour label for the file it's found rather than it's folder as I'd hoped, so I should be doing something else.

Thanks for your time, and for a great product :)

J

Re: Another subfolder question

PostPosted: Mon Jul 09, 2012 8:44 pm
by ecormany
this is an interesting case, and it turns out that it's actually best to write it as one rule.

the general rule of thumb for "run rules on folder contents" is that it should be it's own self-contained rule at the top of the list, but that's not the case when you want to perform other actions on folders other than just traversing the hierarchy. if you put a plain "run rules" action at the top of the list, Hazel will match it and go "ok, the only thing i'm supposed to do with this folder is look inside it. nothing else."

so what do you do? set up a rule that performs actions and runs rules on subfolders. it looks like this:

Code: Select all
if any of the following conditions are met for any of its sub-files or folders
    kind is not folder
    if all of the following conditions are met for the current file or folder
        kind is folder
        color label is X
do the following to the matched file or folder
    set color label X
    run rules on folder contents


note that the nested "current file or folder" actually refers to the subfile/folder, not the parent. the wording is a little odd, but it works!

Re: Another subfolder question

PostPosted: Tue Jul 10, 2012 3:07 pm
by Mr_Noodle
Avoid using the pop-up where you set things to subfiles or not unless you know what you are doing. The rules as you have it now (I replying to the OP here) seem to overuse them.

Looking at ecormany's rule, it looks like it should work. The "current file or folder" target is relative to any enclosing rule so it should correctly match against the subfile/folder being matched. Note that this gives you grey folders all the way up to the top which one of your rules implies though your description didn't.

Re: Another subfolder question

PostPosted: Tue Jul 17, 2012 10:59 pm
by Ynot
I was looking for something like this, and ecormany's solution gave me the part I needed, so I figure I'll share.

Goal: Show me at a glance how to follow folders all the way down to recently edited documents by highlighting all folders that contain files that have been updated in the last 7 days (and all folders containing such files).

Solution (and there may be more compact solutions):

1. Folder Coloring Rule
2. Folder Uncoloring Rule
3. Go into subfolders rule (just the standard one, so I won't repeat)
4. Color recent documents
5. Uncolor old documents

1. Folder Coloring Rule:

If any of the following conditions are met for any of its sub-files or folders:
Color Label is [red]
Do the following to the matched file or folder:
Set color label [red]
Run rules on folder contents.

2. Folder Uncoloring Rule

If all of the following conditions are met for any of its sub-files or folders:
Color Label is [X]
Do the following to the matched file or folder:
Set color label [X]
Run rules on folder contents.

3. [Not included]

4. Color recent documents

If all of the following conditions are met for the file or folder being matched:
Date last modified is in the last 7 days
Do the following to the matched file or folder:
Set color label [red]

5. Uncolor old documents

If all of the following conditions are met for the file or folder being matched:
Date last modified is not in the last 8 days
Do the following to the matched file or folder:
Set color label [X]

Hope this is helpful to some folks.

Tony