How To Automate File Management With Hazel

Published:
Last Updated: Sep 23, 2020

Written by

I always try to automate repetitive tasks, such as filing receipts and invoices. For exactly that reason I created a script using AppleScript to help with those tasks. Now I have discovered an even better way to do that using Noodlesoft’s Hazel. After download and installation, Hazel is accessible through System Preferences or through the OS X menu bar.

I use Hazel to automatically file (rename, move)  the following files:

  • Personal
    • Travel expenses
    • Household receipts
    • Tax-deductible receipts
    • Pay stubs
  • Work
    • Invoices to pay
    • Receipts

Before I can let Hazel do its job, I digitize most everything I get as a hard copy. When I’m at home or at my office I use a Fujitsu ScanSnap iX500* to wirelessly scan to my Mac and when I’m on the road I use an iPhone app called Scanbot. Either way, the scanned file ends up in a folder in Dropbox named Scan. This folder Hazel is monitoring for incoming files. In order for Hazel to be able to easily determine the file’s target location I’m prefixing scanned files:

  • Household receipt: HH-
  • Tax deductible receipt: TAX-
  • Travel expense: EXP-
  • Pay stub: PR-
  • Invoice to pay: INV-
  • Receipt: SEC-

Let me walk you through the rules I have set up by using my household receipts as an example. In Dropbox I have the following folder structure to archive such receipts:

Dropbox > Receipts > Household > 2014 > 05 – May > BestBuy_Dishwasher_2014_05_01_14_33_20.pdf

So I would like Hazel to move the scanned imaginary receipt HH-BestBuy_Dishwasher_2014_05_01_14_33_20.pdf into Dropbox/Receipts/Household/2014/05 – May/BestBuy_Dishwasher_2014_05_01_14_33_20.pdf while stripping the HH- prefix. I admit I haven’t spent a ton of time researching the most elegant way to carry out this task, but here is what I came up with:

1. Add Scan folder to Hazel

To add a folder click on the + button in the lower left and navigate to the folder Hazel should watch. In my case it’s Dropbox\Scan.

Add Scan folder so Hazel can monitor it
Add Scan folder, so Hazel can watch it

2. Create a rule that applies to files starting with HH-

Next, make sure the newly added folder on the left-hand side is selected and then click on the + button in the middle of the dialog to add a new rule. Configure the rule to look for files starting with the HH- prefix and move it into Dropbox\Receipts\Household.

Rules to move files with HH-prefix into Household folder
Rules to move files with HH-prefix into Household folder

3. Add Household folder to Hazel

Next, we’re going to add the high-level target folder (Household) to Hazel so it can watch it as well.

4. Create a rule for the Household folder

Inside the newly added Household folder we’re now going to create a rule that sorts files in the folder into the following sub-folder format: YEAR## – MONTH. For example 2014\05 – May. To do that we first configure the rule to look for files starting with HH-. Then we sort those files into sub-folders using a date-based pattern. So click on the “date created” pattern to add it, then on the folder separator (looks like an arrow) and then on the “date created” pattern again.

Now we have to change the patterns to get us the format we want. To do so click on the first “date created” to bring up the details dialog and then click on the downward facing arrow next to the first pattern. Choose “Edit Date Pattern” and adjust the pattern to show the 4-digit year only.

Change Date Pattern to show year only
Change Date Pattern to show year only

Do the same with the second date pattern to show the 2-digit month, space, “-“, space and the spelled out name of the month.

Date pattern to show month
Date pattern to show the month

Last but not least add another rule (by clicking on the + button at the end of the rule you just created) to rename the file by removing the HH- prefix. You can leave the “name” “extension” pattern but we need to change the name pattern by clicking on it, in order to bring up the details view and then using the arrow down button to change the pattern details. Select “Replace text…” and replace HH- with an empty field.

Remove HH- prefix
Remove HH- prefix

At the end the rules for the Household folder should look like this:

Rules to move files with HH-prefix into Household folder
Rules to move files with HH-prefix into Household folder

Repeat the same steps for other file categories and feel free to change the rules to fit your environment. In case you wonder why I didn’t add the rules of the Household folder to the corresponding rule set of the Scan folder, the answer is that I discovered that the “Sort into subfolder” rule does not work well in combination with other rules.

For instance, I couldn’t find a way to add a “Sort into subfolder” rule to my Scan folder but apply the rule to the Household folder. If you find a better way to do this, please let me know by leaving a comment!

2 thoughts on “How To Automate File Management With Hazel”

  1. Okay – I found your article because I’m trying to figure out how to deal with this issue..

    Hazel, recognizes a file, renames it, moves it and moves into the right subfolder before I actually save the document from scansnap manager. I can see the hazel notifications saying that the file was moved but then I can’t save it because it isn’t there anymore….really maybe not a Hazel problem but a scansnap one. So I end up having to “X” out of the scansnap manager as the file no longer exists…..it was already sucked out and moved. This adds a few extra steps but would like to figure out how to stop having to cancel the scansnap saves so I don’t have to cancel? Hopefully this makes sense. It’s driving me nuts and I can’t find help which means to me that it’s a simple fix and no one else has the problem! Grrrr..

    Reply
    • Hi there,

      I had a possibly related issue with hazel moving partly OCR’d files out of the pertinent folder so that they were not available anymore for the OCR app to complete the job.
      Problem solved by adding a time delay. Added a condition such that files had to be older than 1 minute. Maybe not the most elegant solution but seems to work. Equanimity…

      Reply

Leave a Comment

[Fit In 40 Seconds]
[Fit In 40 Seconds]