Label Documents with Folder and Sub Folder Names

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

Moderator: Mr_Noodle

Label Documents with Folder and Sub Folder Names Tue Feb 04, 2020 11:16 am • by markp
Hi everyone

Hope that you are having a good day.

I'm struggling to set up a rule that does the following when I save a file to a folder

So my folder structure is

Client Name [this is the main folder]
Invoices [this is a sub folder of the main folder]
Correspondence [this is a sub folder of the main folder]
Work in Progress [this is a sub folder of the main folder]
Building 1 [this is a sub folder of the Work in Progress folder]

In the example structure above - when I save a file to say the Invoices folder I need it to tag as Client Name and then Invoices

If I save something into the Building 1 folder I would like it to be tagged as Client Name, Work in Progress, Building 1

Can anyone help me?

Thanks very much.
Mark
markp
 
Posts: 4
Joined: Wed Aug 08, 2018 7:01 am

You can use nested conditions. An example:
Code: Select all
   If (all) are met
      If (all) are met for the (enclosing folder)
         Name matches (•parent name)

•parent name is a custom attribute with a pattern of "anything". That will capture the parent name into that attribute which you can then use in an Add tags action. If the folder structure is predictable, then you can nest the nested condition to get the enclosing folder of the enclosing folder. You'd need different rules to cover the different folder depths.
Mr_Noodle
Site Admin
 
Posts: 8522
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thank you for this. I'm sorry how do I add this to Hazel. Also will this script cover the level of depth mentioned in my post as that's as deep as it will go.

Sorry for asking obvious questions but I'm just really finding my way around Hazel and don't have any scripting experience.

Cheers
Mark
markp
 
Posts: 4
Joined: Wed Aug 08, 2018 7:01 am

Look up "nested conditions" and "match patterns" in the manual. You can only nest a certain number of levels (I believe it's 3).
Mr_Noodle
Site Admin
 
Posts: 8522
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support