Hazel rule script for importing/indexing to a specific group

This script has literally just changed my life!! I’ve been using automator workflows (because I don’t know how to use Applescript) to get my scanned documents from my ActionFolder into the various folders in my DTP database but its very clunky and if DTP is not running and in the same space, then it doesn’t always work.

I’ve just updated all my Hazel rules using this script and it is brilliant so thank you.

A related question: is there a way to use scripting so that when a filed is added to a particular group, you can sort it automatically into sub-groups by date (i.e. year). Say you run the script so that every time you scan a bank statement, it gets put into your Bank Statements group in your database - it would be awesome if it added it to a sub-group according to year and if a sub group for the year was not there, it created one.

Hazel can do this but obviously not if you are running the above script to import documents into DTP instead of into a normal vanilla nested folder arrangement outside DTP.

At the moment, my paperless set up has a group for each tax year with sub-groups for each category - bills, bank statements, deductible expenses etc.

Whether with automator or this script, it means editing each Hazel rule each new year to point to the new sub group.

Maybe I would be smarter to have each category and then sub-groups by year underneath as then it would be easy to manually create them at the end of the year just by selecting all the bank statements for the year and grouping them.

Interested to know what others do?

The reason I have it divided by years is that we are required by law to keep tax documents for 5 years but after that I can prune out the old years - either delete or archive so my database doesn’t eventually grow enormous?