Apply Finder tag to subfolders based on contents

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

Moderator: Mr_Noodle

I am trying out Hazel for the first time, after having been pointed to it from a question I asked here:
https://apple.stackexchange.com/questio ... on-content
as I am looking for a way to automatically apply a given Finder tag to a folder based on its contents.

I read up on how to process subfolders here, https://www.noodlesoft.com/manual/hazel ... ubfolders/
however, I'm unsure how to construct a rule that checks those subfolders for containing files.

This is the scenario:
I have a archive of files stored in several subfolders, like this, where the folders ending on A, B, C etc. are folders that contain a number of different files.

Archive
|
|—— 2015-09-09
| |——2015-09-09-A
| |——2015-09-09-B
| |——2015-09-09-C
|—— 2015-09-10
| |——2015-09-10-A
| |——2015-09-10-B
| |——2015-09-10-C

Now what I want to accomplish is to apply Finder tag "X" to all folders (on the level of those that end on A, B, C, etc.) that contain one or more files with file extension "Y".
So essentially constructing a rule that applies to all folders within the folder "Archive", automatically tagging them based on whether or not they contain specific files. Any way to do that with Hazel?
jandavid
 
Posts: 4
Joined: Wed Sep 16, 2020 2:16 pm

You'll need a combination of two things and it's important to understand the difference between them.

First, you'll need a rule to do the tagging of a folder based on the files within. You can do this using a nested condition (look them up in the manual). Doing that, you can set up a condition to match the files within a folder while the overall rule still matches the folder.

Once that is set up, you will need to have a rule which goes into subfolders, since many of these folders are deeper in the hierarchy. This is an independent rule from the above.

Note that you will need to add a condition to the first rule to somehow only apply to the folders either at a certain level or whatever it takes to identify the A, B, C folders otherwise it will end up applying to the folders above it as well.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thank you so much, this is great!
I think I'm almost there, but for some reason it doesn't work on the subfolders.
This is how I have it now:

For my top level folder (called "Test") I have two rules.
One is simply the "Go into subfolders" rule (per the manual)
Code: Select all
If all of the following conditions are met
Kind is Folder
Do the following to the matched file or folder
Run rules on folder contents

Then the second rule I called "Label"
Code: Select all
If all of the following conditions are met
Kind is Folder
If all of the following conditions are met for any of its subfiles or subfolders
Extension is pdf
Do the following to the matched file or folder
Add tags "To Do"

It works for the folders on the first level below the "Test" folder but not for any of the subfolders of these. What am I doing wrong?
(I specifically need it to match the second level of subfolders.)

Also, for current purposes it's fine to have it apply to any subfolder no matter at what level, as the first level subfolders won't ever get any of the files whose extensions will trigger the rule, so it won't bother to have it apply there too.
However, if there was a way to specify a specific level of subfolders I'd be eager to learn how to do that for future reference.

I appreciate your help!
jandavid
 
Posts: 4
Joined: Wed Sep 16, 2020 2:16 pm

You might want to swap those rules. I think every folder ends up matching the first rule so the second rule isn't reached. You can use the Rule Status UI to check that.

For the tag rule, you can use a condition using Subfolder level to limit it to folders a certain number of levels deep.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Hmm, I swapped them, but it still doesn't detect the subfolders.
Also in the Status UI, it only shows the folders on the first level. What am I doing wrong?
jandavid
 
Posts: 4
Joined: Wed Sep 16, 2020 2:16 pm

Actually, I guess you want the files to match both rules. In the first rule, add a "Continue" action to allow it to proceed to the next rule even if there's a match already.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Awesome, yes that did it.
Thank you so much!
jandavid
 
Posts: 4
Joined: Wed Sep 16, 2020 2:16 pm


Return to Support

cron