Page 1 of 1

Label Documents with Folder and Sub Folder Names

PostPosted: 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

Re: Label Documents with Folder and Sub Folder Names

PostPosted: Tue Feb 04, 2020 12:37 pm
by Mr_Noodle
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.

Re: Label Documents with Folder and Sub Folder Names

PostPosted: Thu Feb 06, 2020 8:34 am
by markp
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

Re: Label Documents with Folder and Sub Folder Names

PostPosted: Thu Feb 06, 2020 11:23 am
by Mr_Noodle
Look up "nested conditions" and "match patterns" in the manual. You can only nest a certain number of levels (I believe it's 3).