Something I never thought of doing in Hazel before

I never thought of doing this in Hazel before, so I am posting in case this is useful to anyone else.

I have a large number of Hazel rules that are geared towards automatically detecting the content of files (downloaded and scanned) and renaming the files appropriately and then moving them to the proper destination folder. Sometimes I want have dynamic rules, eg rules that depend on the file name or content. For example, I might want to apply tags to a file that are based on content. I have often written custom scripts (usually Python or AppleScript) to carry out custom actions. Tagging is particularly difficult as you cannot tag a file (easily) in AppleScript or Python, and I wrote my own utility in Swift to do that.

I realized today that I could use the ability of AppleScript (or JavaScript) in Hazel to create custom attributes to carry out much of this functionality.

Here is a test demonstration:

The AppleScript, as a demonstration, is simply:

And the custom attribute is created as part of the Hazel action:

In creating the add tag rule, you use a Dynamic Tag:

And you are done.

I can see using this in combination with data detectors in the Hazel rules. For example, I may match on an account number or a billing date, and can then use the AppleScript and the matched attributes for the date to pull out month or year or vendor or account number, and then create tags or other functionality.

I never thought of using Hazel in this manner to create custom tags.

Maybe this is just obvious to everyone, but maybe someone will find this useful.


That’s very clever, thanks for sharing!