First crack at TextExpander and Hazel automation

22 Aug 2012

I’ve been experimenting with some new paperless workflows and thought I’d tell the Internet about them. You may find this useful. Or not. First, giving credit where credit is due I’ll point you to the Mac Power Users podcast which features paperless workflows and cool automation tricks regularly. The hosts of that show, David Sparks and Katie Floyd, mention the automation tool Hazel nearly weekly, and it forms the core of this workflow. I can also recommend David’s book Paperless which covers these kinds of scanning and filing automation tasks in great detail.


The goal is to automate the process of scanning and uploading recipes into Evernote. This is a modest goal, but I learned long ago to spend some time on simple cases before diving into the more complicated ones. This bears repeating with emphasis.

Do spend time on the trivial cases. The problems you encounter in doing so will be more manageable and easier to troubleshoot. You’ll create solutions that can be saved and referred to later and quickly digested—not so complex that it will take a long time to recall and decipher the approach you used. You’ll find it easier to search the Internet for the help you’ll almost certainly need. (You will have the opportunity to post the definitive solution to the complex problems later and bask in the Internet’s glow of appreciation.) Be patient, and start with the simplest possible thing that will get the job done. Make it elegant later.

Here’s the basic sequence of steps which I’ll elaborate below:

  1. Scan a paper recipe card or, alternatively, do a screenshot of an online recipe with a utility like Skitch.
  2. Use a TextExpander snippet to give the scanned document or screenshot a specially crafted filename.
  3. Scan (or drag) to a folder watched by the Hazel utility.
  4. Watch the magic happen.

Step #4 is the magical part.

I’m going to be experimenting with more specialized document scanners in the coming weeks, but for now I’m using the flatbed scanning capability of the multifunction printer in my home office. I typically use the Image Capture utility included with OS X for capturing the scans. There’s nothing fancy about it, but it can import images from networked scanners so it does the job for me at this point. The trick to get this workflow going is the TextExpander snippet that I use in the scanning dialog box (or after the fact in the Finder) to set the filename of the resulting PDF to something my Hazel rule will recognize and process. More on the Hazel rule later.

The TextExpander snippet is triggered whenever I type the string s>recipe in any application. So whether I name the file within the Image Capture interface before it’s scanned or after the fact in the Finder, typing the TextExpander snippet produces a dialog box like this:

TextExpander snippet for renaming a file

The resulting filename contains the basic information that will eventually feed into Evernote: the name of the recipe, and a list of tags for the note. The next step of the workflow (step #4) is triggered automatically when the scanned file lands in a folder named Action whether it’s scanned there directly or dragged in manually.

The Hazel utility regularly scans the directories you set it to watch and applies a series of rules to the files it finds there. Here’s the rule I defined to identify new recipes in that folder:

Hazel recipe showing steps to send to Evernote

The Hazel rule has two significant parts. First, it finds the files that contain scanned recipes by looking for the string recipe - in the filename of any PDF files in the folder. Once it locates the scanned recipes it applies an AppleScript to each one to parse the specially crafted filename to extract the name of the recipe and the recipe tags and then creates a new Evernote note with that information. Finally, if the Evernote note was created successfully, it moves the original file to the Trash.

I hope this post piques a bit of interest in scripting and automation among some readers. I’ll do some more posts on the topic as I continue to develop new workflows. Feel free to leave a comment if you have any questions, and I’ll do my best to answer them or point you to a better source of information.

By the way, here’s the Jalapeño Jelly recipe.

2 responses to First crack at TextExpander and Hazel automation

  1. Hi: I need basic Hazel-ish help. Can I email you my request and if so, where? Thank you!

  2. Susan,

    The best place for support is the Noodlesoft Hazel support forum here: http://www.noodlesoft.com/forums/viewforum.php?f=4

    There are a number of expert users who do a great job answering questions.