Automate Archiving Bank Statements to Evernote in macOS

I’ve been manually archiving bank statements (PDF files) to Evernote for a while. And frankly it’s taking me a fair amount of time to do it “properly”. By that I mean:

  • One statement saved in a single note.
  • Note name should reflect which card/account the statement is from.
  • Note name should reflect which period the statement is from.
  • Note should have proper Creation Date matching the statement. It helps sorting.
  • Note should have proper tags to help searching.

So it’d take much longer than just using Evernote to clip the PDF files.

And finally I got tired of it and decided to automate this.

Demo video

When I drag the downloaded statement files into the “Dropbox” folder, they get automatically archived to Evernote and then deleted from the folder.

The solution

… is fairly straightforward.

Step 1: create a Folder Action in Automator to watch new files for a particular folder.

Step 2: for each of the new files, create a new note in an Evernote notebook with that file as the attachment.

Since this is a pretty generic step, I created a Script Library for it. See Evernote.scpt in the code below.

In my case I want all statements to be in the Finance notebook and tagged with the bank info and some extra tags to help searching. I want the name of the note to be some identification of the card and the date of the statement.

Then here’s the slightly more tricky part. AFAIK, AppleScript is not particularly good at processing strings. And because I know JavaScript better, I decided to parse the statement filename in JavaScript.

What I need is the date info in the filename and make sure the filename looks like what I’m expecting. That’s what parseFilename in 2 - Parse filenames and save to evernote.js is doing.

So why do I need 1 - Get paths and filenames from aliases.scpt at all? Well, this is embarrassing. Half way into the JavaScript I realized that I can’t use nodeJs modules like path to help me with parsing the input file paths. Manually splitting the string looks messy. Eventually I learned that getting the filename from the path is very easy so I added this extra step to convert the list of aliases to a list of descriptors that have both the path info and the name info.

I encountered a strange exception here: when I tried to save the original alias into the path property of the descriptor, Automator simply crashes.

Another caveat is, given the way of reading a property from a descriptor is propName of descriptor, the property name can’t be some pre-defined keywords, such as path. So I had to change it to "thePath".

The Automator Workflow

The code