Tagging All the Files with Hazel
What is Needed?
A reader sent me an email asking about a refinement to my filing system. I've had something like this on my list for a while so off I went. Because Hazel is such an awesome program, it was fairly straightforward with only two twists.
The suggestion was to tag a set of nested folders with an individual tag for each folder the file is nested in. Here is the reader's description of the system.
What would be better (I think) would be a method to apply independent tags as Hazel moved downward through a file structure. For example, if you had a file structure organized like this:
Business —> Client Name with each Client Name folder having subfolders for Correspondence, Invoices and Contracts
then files at the level of Invoices would get three separate tags: Business, the name of the Client, and Invoices. Files at the level of Client Name would get two tags: Business and the name of the Client.
Independent tags would allow you to look across multiple Clients for all Invoices - say those within a specified date range. That is not possible with the hierarchical folder structure that I describe above, but would be possible if the folder names were converted to separate tags. IMO: The ability to look at “Invoices” as a separate searchable term substantially increases the information contained within the hierarchical structure. Its value extends beyond the administrative convenience of not having to worry about folder structures.
Reader suggestion for tagging a substructure. Accomplished via a set of 4 rules in Hazel
Setting up Hazel
First, you need to set up Hazel to crawl through a folder substructure. This is described in a couple of places here on this site, Gabe at Macdrifter, and by Mr Noodle. Simply put you put this rule on the top-most folder above the level where you want your files to be tagged. In this case, we want the Business folder to be tagged so I set this rule on the next folder up which I called Testing.
This rule makes Hazel run around in the folder substructure with some sort of coding wizardry.
Then you add a rule for each level of folders you want to tag. In our example, we have 3 levels...Business, Client, and Contracts / Correspondence / Invoice. So 3 rules to cover this. I had originally thought that 1 rule could do it. However, I couldn't come up with a simple way to make it work so I split the task up. Each rule uses the Subfolder Depth condition in Hazel. So, this is a good opportunity for a reader to suggest an improvment and I can link to it! That's it in a nutshell.
A few items, honestly, would be best covered in a screen cast. Namely, making nested rules in Hazel (simply hold option when pressing the + sign to add a condition) with custom tokens for tags. I'll put in a few screen shots to try and bridge the gap until I hopefully put together a screen cast. I think the screen shots should get folks most of the way there with a little trial and error. See the bottom of this post for a few screen shots on custom tokens.
Rule for tagging files on sub level 1
Rule for tagging files on sub level 2. The second if statement is nested.
Rule for tagging files on sub level 3
This shows the custom token detail. It is named Tag1 and matches any folder name. Then this custom token is applied to a tag via the dynamic tagging below.
Here the custom token is selected to apply the tags.