Date Matching in Hazel

Those of you who crave a paperless workflow will, no doubt, have run into the same problem that I have when it comes to naming your documents effectively. That is, having an accurate date in the document name without manual intervention. 

I’m going to quickly outline my own workflow for automatically naming documents, such as bank statements, invoices, receipts etc and you will see that it can be leveraged for almost any situation you see fit, thanks to Hazel’s ability to dive into documents and retrieve a date. 

Let’s start with my Downloads folder. Almost everything that comes into my machine from the Internet will hit this folder as a point of entry, so the first thing that happens is I have a Rule run called OCR Documents

 

The OCR Documents rule is a very simple one, in that it checks whether or not the file is a PDF or not. If it isn’t, it carries on down the list of rules to process. If it is, however, then it will run an AppleScript. 

 

The AppleScript simply calls PDF Pen Pro and performs OCR on the document, before closing again, all in the background. 

 

Having the OCR Document rule at the top of the rule list for my Downloads folder ensures that all documents that come in can now be scanned for keywords or, more importantly, dates to allow them to be renamed and filed appropriately. So we work our way down the list of different statements, invoices etc that we might need to process. Let’s take the Current Account Statement as an example. 

 

The If statements will change fo ryou based on your own circumstances. Myself, I find that having a line for the Account Number a line for the word Statement with bank name, as well as the Date Match (which we are about to dive into) are sufficient to identify this document as a Statement. Now what is the Date Match all about and how do we find it? 

Well, Date Match (you can call it any name you want) is a custom search you are creating in Hazel that is going to scan the contents of your document for the occurence of a date. I’m going to recreate it using these steps so you can follow along

Click on the + button to the right of the last rule parameter you created and change the left hand dropdown to Contents and the second one to contain match. You will then have a pop up box appear, asking you to enter some criteria for the rule to match to. Click the Custom Date button. 

 

You now have a second pop up box appear. Here you will name your custom date (This is where I entered Custom Match - choose whatever you like) and then select the format the date needs to take. Remember, this needs to be in the same format that that the date appears in the document, otherwise the rule will not process as a condition will not be deemed to have been met. 

For example, if you have a date in your document of 1st Sep 2015, this needs to be the pattern you select in your Custom Date search. Fortunately, you don’t have to rename your document with this same format. 


When you click Done, you return to the first pop-up window. If you look to the bottom, you will see where, exactly, you would like this date to match. Should it be the 1st date in the document, second etc. (You can also choose from the end as an option here). This is clearly dependant on where the dates generally appear in the document you are trying to file. Bank Statements always use the same template so I’m safe in the knowledge that I can use the 1st occurence of this date as my base for renaming the document. 

I now let Hazel rename the document. I choose to use the newly created Date Match as the first part of the name, however I can edit this token now to display the date in a different format. I name my documents as follows:

YYYY-MM-DD name_goes_here.pdf

That is how I use Hazel to deep dive into documents, retrieve dates and work it’s magic. It’s pretty cool, I love the fact that the only time I have to think about this is when I’m setting up the rules and the great thing is, I always discover new stuff when I open Hazel up and start working through it. It’s great. 

How do you use Hazel? Do you have any tips you’d like to share with everybody? Drop me an email or comment here and I’ll be sure to include them in the next newsletter.