How to Use Hazel to Save Bills to Evernote Automatically

We will be sitting in a self-driving car in 2020, but why are we still managing invoices and receipts manually? I went paperless from day one by having invoices, receipts, and billing summary sent my email address. The problem is I detest organizing them manually in Evernote, so I come up with this setup to automate the whole process.

I have two notebooks named as Receipts and Bills. Whenever I receive a receipt or billing summary, I will rename the files and move them to respective notebook. I can handle it in the beginning, but as I increase the number of subscriptions, I find that spending few hours a month to organize these documents is not worth my time.

One day, I decide to write down the steps I follow to properly put these documents in place: I receive an email, the email contains attachment, I download the document, I rename it, and I move it to Evernote.

None of these steps require me to monitor the process. With a few simple tools like IFTTT, Dropbox, and Hazel, I can already automate the task.

If you’re familiar with these tools, I will share a brief summary of what we will be doing.

The main idea is to use automation service like IFTTT or Zapier to detect attachment sent to our email address, which later are saved into Dropbox. We will then configure few Hazel rules in a folder storing those files, rename each file, and run an AppleScript that move the documents — also with proper tags — into Evernote selected notebook.

Here are the list of tools and accounts you need to make the setup works:

  1. IFTTT or Zapier account. If you’re new to automation, you can start by creating an IFTTT account for free. It also have ton of recipes you can run. You’ll be using IFTTT to be the bridge among the services we will be using in this guide.
  2. Gmail. We’ll be using Gmail because it’s free.
  3. Evernote for Mac so you can run Evernote AppleScript.
  4. Dropbox account and Dropbox for Mac.
  5. Hazel to create rules that detect files and run Evernote AppleScript.

Setup IFTTT Recipe

Sign into your IFTTT account and activate Gmail and Dropbox in IFTTT Channels. Now you can use any recipes that require those two channels.

The automation begins with IFTTT run a recipe that saves any new email with attachments to a Dropbox folder. You can directly activate Save all your Gmail Attachments to Dropbox recipe to complete the setup.

IFTTT Dropbox Channel Integration

Set the folder path to Apps/IFTTT/ so you can place IFTTT along with the rest of third party integrations that you have granted the access to your Dropbox account.

Now you have the core step implemented. Now every time you receive an email with attachments, these files will show up in the Dropbox folder. We’re not done with Gmail yet because we have to clean up those emails.

Cleaning Up Matching Emails in Gmail

If you want to automate, you should automate every step. Wouldn’t it be ideal if Gmail can automatically archive those emails with receipt and billing so they don’t fill up your inbox?

Since you know for sure who will send you those billings and invoices, you can set up Gmail filters to archive those emails whenever they arrive at your inbox. Gmail filter is a powerful feature that you can bring in your arsenal in managing emails.

Visit Gmail Filters Settings and create a filter with the following rules:

1
2
3
From: <[email protected]>
Has the words: <the subject of the email, or the common words in the email content)
Has attachments: <check>

Gmail Filter

It can be as simple as filling From field and leave the rest of value blanks, or as complete every form fields. The main point is to create a rule that can accurately detect the emails that contain receipts and billings.

Gmail Filter Action

Choose Continue and enable Mark the email as read and Skip the Inbox (Archive it).

Setting up Gmail filter doesn’t stop IFTTT from detecting new email with attachments.

What can you do if you receive the attachments from different email address? IFTTT doesn’t allow you to connect to more than one Gmail channels. You can setup an IFTTT connected Gmail channel as a forwarding email address in other accounts, and once verified, you can create filters to forward emails with attachment to your Gmail IFTTT account.

Hazel Rules for IFTTT Folder

Create a new folder inside ~/Dropbox/Apps and name it Evernote. The Dropbox folder structure should look something like this:

1
2
3
4
Dropbox/
  Apps/
    IFTTT/
    Evernote/

Having a dedicated folder for each app that runs Hazel rules allows us to organize and manage the rules later. The point of separating rules per folder basis is to address a question like, “Where did I run this rules that trigger Evernote AppleScript?”

So why didn’t we just configure the IFTTT recipe to save every incoming attachment to Apps/Evernote/?

Remember that not all attachments saved inside Apps/IFTTT will be sent to Evernote. Sometimes you want to move the attachments to Downloads or Desktop. IFTTT folder is the main repository that decides where the attachments or files must be dispatched.

Now that the folders are available. Drag IFTTT folder into Hazel and create a new rule called “Move to Evernote”. The rule does only one thing: move any matching files to Apps/Evernote/ folder.

Hazel Rules Move to Evernote

The screenshot above shows how I use the standard filename and insurance number to decide when to move these attachments to Evernote folder. Unless the attachments meet the rules conditions I set, they will stay inside IFTTT folder for other rules to process.

Moving forward with IFTTT folder, you can come up with another rule such as “Move to Download”, “Move to OmniFocus”, or “Move to Things” where each folder can run their own AppleScript.

Hazel Rules for Evernote Folder

If you have come this far, try to send an email with attachment to your IFTTT Gmail account, and see if the attachment is saved to Evernote folder. Remember to force trigger the recipe if you don’t see it appear immediately.

Make sure you can find the attachments in Evernote folder. If the attachments are still inside IFTTT folder, you need to preview the rules you configured for IFTTT folder.

Great! Now there are only a few steps left to complete our setup. You will have to do a several things here:

  1. Decide the final filename format.
  2. Create a rule to detect the attachments.
  3. Create an action to rename those attachments into the final filename format.
  4. Create an AppleScript action import these attachments into Evernote.
  5. Move these attachments to Trash.

There are no rigid rules when it comes to naming these attachments. In my case, I prepend the service name with imported date. Here are some examples of how I name them:

1
2
3
4
5
<created date> <service> <attachment name>
Example:
2014-11-20 Telkom group_E09876543210
2016-05-31 PAM 2016 October Bill
2016-05-30 Allianz Premium Notice_012345678810

For every service, you will need one rule. Each rule can have multiple matching patterns to detect attachments. If you want to create a complex matching pattern, try nesting rules.

Name the Hazel rule so that you can understand what it does without having to check the rules. Here are some of the rules I run for Evernote folder.

1
2
3
4
5
Save to <notebook> as <service name>
Example:
Save to Billings as Telkomsel Halo
Save to Billings as Telkomsel
Save to Billings as Allianz

Each service usually has their own file naming convention, and they rarely overlap. Most of the time, your unique number can be found as part of the attachments name.

Here is an example of Hazel rule that checks for Telkomsel Halo attachments and saves it to Evernote.

Hazel Rules Check Filename

The rule is pretty straightforward. It checks for matching attachments, rename them, and run an AppleScript that imports them to Evernote.

Here is what I have for Rename field value:

Hazel Rules Naming Filename

You can edit the date pattern by clicking on the down arrow button beside date added. The ideal format is still YYYY-MM-dd when it comes to specifying the date prefix.

The final step is to fill in the AppleScript section. Click Edit Script and paste the following script into the text field. Rename “Billings” to your notebook name.

1
2
3
4
5
6
7
tell application "Evernote"
    if (not (notebook named "Billings" exists)) then
        make notebook with properties {name:"Billings"}
    end if
    activate
    create note from file theFile notebook "Billings"
end tell

The rules are fairly self-explanatory. If the notebook Billings doesn’t exist, it will create one on your behalf, and followed up by adding a new note from matching attachments. It will also delete the attachments once they are imported.

If you make sure the notebook exists, the script can be as simple as:

1
2
3
4
tell application "Evernote"
    activate
    create note from file theFile notebook "Billings"
end tell

If you want to tag the note with AppleScript, you can add tags <name of tag> at the end of create note command like this one:

1
2
3
4
tell application "Evernote"
    activate
    create note from file theFile notebook "Billings" tags "Phone"
end tell

The most important thing is the notebook name which you must replace with your notebook name. Remember why I told you each service needs their own rules? Sometimes you want to save the attachment in a different notebook — billings, receipts, or shared notebook. You can get this setup by creating a new rule that detects only the files you want to move to a different destination.

Now, try to copy some attachments into Evernote folder. Preview and run the rules to see if they’re imported successfully into Evernote. If you can see them in Evernote, the setup is complete.

By now every step should be ready. You should forward some emails with attachments to your IFTTT Gmail account and see if you can find the attachments in Evernote. Trigger the IFTTT recipe manually if you don’t see the files in your Dropbox.

If you find this guide useful, please share it with your friends. Send me an email if you have any questions about this setup.