jarrodwhaley.com

I make films. I'm also a nerd.

Automatically Back Up Files To Evernote With Hazel

I keep almost the entirety of my life in plain text files–notes, ideas, to-do lists, movies I want to watch…pretty much anything that can be stored in text. It’s easy to find things when I need them with a search in Alfred or nvALT, and I know that my data will be safe for the long haul; plain text has been around as long as computers have existed, and it isn’t going anywhere. I do, however, like to back up all that data both locally and remotely, and Evernote does a great job of that. I also like to automate the process, so that I don’t ever have to think about any of this.

I’m a pretty heavy user of Evernote, though I no longer use it for actual notes1. It’s a great place to dump a backup for a couple of reasons: 1) it’s extremely reliable, and 2) the ubiquitous sync means that my backup will instantly be available on all my devices and from any browser on any computer at which I might find myself2. For these reasons, I have Hazel run a couple of scripts every week which archive my notes and then add a time-stamped .zip to my Evernote account. Note that this method will work for any kind of data you have on your hard drive–not just text files.

Dependencies

To make this work, you need Hazel, of course. And it works best if you have a desktop Mac which is running at all times–preferably with an open instance of Evernote, so that the backup files get synced immediately.

Hazel Rule No. 1

My usage involves backing up an entire folder once per week, and I’m going to proceed with that taken into account. It’s not that dificult to tweak what’s below if, say, you want to back up a single file every night, however.

First, have Hazel watch the folder you’d like to back up. Then you’ll want to add a rule (mine is called “archive files”) which .zips up those files based on your conditions: mine is run every Sunday night. Under “Do the following to the matched file or folder,” you’ll want to add an action with the selections “Run shell script” / “embedded script,” and then paste the following into the “edit script” window (with /bin/sh in the “shell” field):

cd ~/path/to/folder/
zip your_backup_filename_`date +%Y-%m-%d`.zip *.*

You’ll want to edit the file path so that the script knows where your files are, and you might want to tweak the name of your backup file to suit your needs. By default, the script will insert an ISO 8601 datestamp (e.g. “2013-06-23”).

Hazel Rule No. 2

Now that we have our archive, it’s time to tell Hazel to send it to Evernote. I’ve done this by setting up a second Hazel rule which runs on the same folder five minutes after the rule we set above3. This rule will also delete the .zip archive from the hard drive after it has been successfully added to Evernote. Here’s a screenshot of my settings, for simplicity’s sake:

screen shot, hazel

After you have your new rule set up, you’ll need to add the following AppleScript to the “edit script” window:

Edit the Evernote notebook specified to that of your choice, and edit the tags as necessary (or remove them, if you like).

Wrap-Up

This all sounds horribly complicated, but it’s not really that difficult. And remember, you’ll do it just once, and then you’ll have an automated backup that you’ll never have to worry about again. I hope this setup proves as useful to you as it has to me. Feel free to contact me on Twitter or ADN with any questions you might have.


  1. It only supports rich text (and therefore mucks everything up with weird formatting) for one thing, and the apps are way too slow for the quick retrieval that I need when looking for a note. Still, Evernote has its uses: it works best, I believe, as a giant repository for backups, recipes, menus, Web clippings…I kind of think of it as my long-term digital memory, where my text notes are more analogous to the short-term memory. 
  2. Dropbox would probably work equally well, and that is in fact where I keep the bulk of my notes–but I prefer to use it only for my day-to-day work and to keep my backups elsewhere. 
  3. This way, we’re sure that the .zip file exists before we try to do anything with it.