02/14/15 13:56:27

Automating Invoices With Hazel

I’ve been working on a new way to automate my invoicing system for a while now. It’s been annoying me that I have to do so much stuff by myself where I could just have the computer handle it for me. It may be discouraging to some because one might feel they miss out on an invoice, but honestly I haven’t because I still see every invoice.


Hazel is obviously the key to the system.

I don’t think I have talk about my invoice naming scheme, but TextExpander and Hazel are able to help me here:

%filltext:name=Invoice Date(YYYYMMDD):width=8% - %fillpopup:name=Payee:MasterCard:VVS:default=%%fillpart:name=Non-Predefined Payee?:default=yes%%filltext:name=Name:width=30%%fillpartend% %filltext:name=Invoice Number:width=15%%fillpart:name=Invoice Period% - %filltext:name=Start Date:width=8%-%filltext:name=End Date:width=8%%fillpartend%

In pseudo-blocks this means:

{{Invoice date in YYYYMMDD}} - {{Payee}} {{Invoice Number}} - {{Invoice Period Start}}-{{Invoice Period End}}

The good thing is that Hazel is able to do almost everything by itself. I would recommend that you check out my Hazel tutorial for the basic and other workflows, but this goes beyond my tutorial screencast.

I have a folder for invoices, named Filed Documents. Hazel is watching this folder for new documents coming in. I have several folders created for parties I receive invoices monthly, and I will only highlight one or two, as example. The others follow the same principles.

Invoices That Have All Information in Their Filename

When an invoice has all the important in the filename, it’s easy. Just setup a Hazel rule where:

NamematchesToken for invoice number - Token for payee - Token for …

Tokens allow to re-use text elements from the conditions, in the actions below. With a text token that matches 6 consecutive digits, labelled invoice number, you can use the rename action to use the invoice number token to set the new filename.

Note that you can also do a lot more stuff, as you can see in the picture:

Invoices That Have No, Or Almost No, Information in Their Filename

Thank you, everyone, for these by the way!

If I wouldn’t have Hazel, this would be much more complicated. Hazel is awesome in the way it can handle these types of documents, because Hazel has a condition where it can match the contents of a file.
As we’ve just learned, when Hazel can match something, we can make tokens out of it.1

In the worst case the filename only contains a 12 string long cryptic filename. (Kabel BW, you are the most awesomest folks of all!) Luckily the text inside the PDF is not as cryptic. Normally a payee would write things like:

Invoice Number: 23894239-W30

Hazel can search for this entire text, but it can also match it. Create a condition that matches for:

Invoice number{{anything}}{{8 digits, followed by "-", followed by 1 letter and 2 digits}}

Hazel will match this text and we are able to use it as an action. Of course the same works for invoice month, and year, too. You can get very creative here!

Invoices Where Hopfen And Malz is Verloren

The German saying “da ist Hopfen und Malz verloren” means “it’s hopeless”. Where it’s hopeless to auto-file, I have one more rule at the very bottom that looks for a {{4 digit}} token as year, and a {{2 digit}} token for the month. If Hazel find these, then I can at least sort them into the year and month subfolders. Oh well.

More on the workflow

This workflow is more elaborate as it looks, because my tax accountant needs to get new invoices regularly. This is why I also have a Copy action at the end. This copies all new invoices to a folder where I keep everything new, temporarily. Every 1st of the month I move everything to a new folder that gets auto-uploaded to my consultant, so she can work with it. (This goes beyond this post, but I’ll give you a glimpse on this auto-copying thing.)

It’s really not complicated. I watch this folder, and every first of the month at a specific time I sort everything into a subfolder. Another action runs a couple of minutes later and does the uploading.

  1. Want something even more powerful? Hazel has an option for “everything” this contains all the information Spotlight indexes, you can create tokens out of almost everything.