Hazel and DEVONthink 2 - Choosing a Target Database

In my previous post on using Hazel and DEVONthink together, I showed you a system I use to automatically get files and documents into the DEVONthink Pro Office Global Inbox.

Did you know, however, that is possible to import content directly into a database of your choosing? It DOESN’T have to just move to the Global Inbox?

Full credit to Alan Duncan of [ojisanseiuchi.com] for this nugget.

Here is how:

When you have configured your Hazel rules to identify the files that need to moved, add this AppleScript to the actions that will be carried out:

tell application id "com.devon-technologies.thinkpro2"
    set img_ib to get record at "/Inbox" in database "Business"
    import theFile to img_ib
end tell

This script will tell Hazel to take the content we have already identified and import it into my Business database. To change the target database, simply modify the name in the script.

Couldn’t really be any simpler at all could it?!

Thanks Alan.

Making DEVONthink and Hazel Play Nicely

Before I move on with this post, I'm going to make a couple of assumptions. I'm going to assume that you already understand that Hazel is an amazing application for macOS, that watches over folders in some form of virtual nanny-state, performing file actions on your behalf whilst you get that busy work done.

I'm also going to continue on the basis that you know about the awesome power of DEVONthink Pro Office, the Database/Paperless Office/Finder Replacement/All round swiss-army-knife-type-storage-app for macOS.

They are both amazing applications and I couldn't imagine having to live without either of them. However, after reading various forums and listening to some of my favourite podcasts, it seems that the general impression is that you can't have a workflow that includes them both. Using Hazel to rename files isn't possible within DEVONthink itself.

While the statement above is largely true, a small amount of lateral thinking can, however open up some possibilities.

I'm going to walk you through the setup I have employed to allow for the renaming of files with Hazel and subsequent import into DEVONthink Pro Office.

1) All files downloaded to my Downloads folder (the default)

2) Hazel watches this folder and automatically performs OCR on any PDF files that appear, using AppleScript and PDFPen Pro

3) These files are then renamed and moved to a Holding Folder I have in Dropbox.

4) Using the built-in Folder Actions for DEVONthink, a script runs on all contents of the folder. This script will Import, OCR and Delete the original file.

Dropbox Holding Folder

The first stage is to set up a Holding Folder. Now this Holding Folder has one purpose and one purpose only. It will perform a Folder Action that will Import a file into DEVONthink, perform OCR (Optical Character Recognition, making the contents of the document searchable) and Delete the original. This folder is the final place files will reside before import into DEVONthink.

The OCR that will be completed in this stage will be using the ABBYY Fine Reader Engine, arguably the most powerful OCR software on the Mac and built-in to DEVONthink Pro Office. We're going to be performing a 'lighter' (yet still powerful) OCR at an earlier stage, so as to rename the file effectively, however the final OCR will take place here.

Why have I specified that this should be setup as a Dropbox folder? Well, firstly, any folder connected to a Cloud Service is fine (Google Drive, OneDrive, iCloud) - I just happen to use Dropbox extensively. Secondly, I find myself scanning and submitting business expense receipts from iOS a LOT. I use PDFPen Scan+ to scan the receipt, I rename with a TextExpander snippet before sending it directly to my Dropbox Holding Folder. When it reaches my Macbook, the Folder Action kicks off and the file is imported into DEVONthink.

Assigning Folder Actions

Assigning the Folder Action to your newly created Holding Folder is a simple process.

  • Open Spotlight
  • Search for Folder Action Setup
  • Click the + button on the left hand pane. Navigate to the Holding Folder you wish to assign the action to.
  • You will be presented with a list of scripts to assign. Select Devonthink - Import, OCR and Delete.scpt

Please note, you must have the scripts for DEVONthink installed. If you don't see any DEVONthink references in the box of assignable scripts, install them by clicking on DEVONthink Pro Office in the menu bar, select Install Add-Ons and tick the check box for Folder Actions Scripts.

 

Great stuff. You now have a folder that will act as a direct conduit between yourself and DEVONthink that is accessible from anywhere you have an Internet connection.

Hazel Rules

OK. Now, we need to set up some Hazel rules. The question we need to ask ourselves, however, is where should these rules be applied? We've set up a Holding Folder, which is going to Import, OCR and Delete thanks to the Folder Action we assigned, yet this folder needs to be the last stop for the file - the final conduit between Finder and DEVONthink. Therefore I apply the majority of my Hazel rules to the default Downloads folder. These rules will carry out some OCR (using PDFPen Pro from Smile Software and subsequently rename the file based on the results.

I'll refer to you an earlier post on Date Matching with Hazel which runs through the process of scripting the OCR, looking for a date within the contents of the document and subsequent renaming.

The only part you need to add to the rule, in order to import into DEVONthink, is to move the file into your Holding Folder once renaming/tagging etc is complete. (Remember, DEVONthink recognises Finder tags, so you can use Hazel to pre-tag your files before they hit your DEVONthink Inbox)

You can make a lot of changes to the workflow above to suit your specific needs. I know that this works for me and apart from the odd tweak here and there, I'm very happy with how it runs.

There will be a video posted soon that walks through this process in finer detail - sometimes screencasts work better than text ever can, so watch this space and I'll let you know when it's ready!

Renaming Downloaded Images with Hazel

I've decided that every single blog post I do should be accompanied by an image file. Not very scientific, basic common sense really, which is something I can safely say I lack from time to time. So in order to find these images, I do what everyone else on this planet does in the same situation and trawl through Google to find one that suits my needs. 

The problem I have, however, is as follows. When I download the files and then try to find them in Finder, when I look in the Downloads folder, instead of finding a jpeg file, I find a file that is simply called Unknown. 

Now this isn't really a problem. I can simply Ctrl + Click, rename to (filename).jpeg and it magically turns into an image file again. This is OK in principle, but I don't want to have to do this workflow every time I download an image file. This is quite time-consuming when you multiply it out over the course of a month. 

Cue Hazel....again. 

After configuration, Hazel now looks at my Downloads folder and looks for files contained within that are called Unknown. It will rename them to the Current Date #.jpg (for example, 2014-07-18 1.jpg). 

This happens within around 3-5 seconds of me downloading the file. Absolutely brilliant. 

What I also decided to do, in order to keep things nice and tidy, is to automatically move those files into a Dropbox folder called Website Images - and it tags them as well, with the same name, in readiness for any potential iOS 8 interaction. 


Using Hazel with DEVONthink

I love Hazel. I love DEVONthink. So imagine how much I love it when I can get these two products to talk with each other. It's pretty awesome. 

As you may or may not know, Hazel is a housekeeper for your files. You set it to watch a partiular directory and depending on the actions you have assigned, you can move, rename, delete, tag - the possibilities are so varied, you really have to go to Noodlesoft's site and check it our for yourself. 

I use DEVONthink Pro Office for my Paperless office setup and one of the things that I find myself doing every month without fail is downloading my financial statements as PDF's from the relevant websites, renaming them, sending them across to DEVONthink, tagging them and then filing them appropriately within one of my DEVONthink databases. It would be fantastic if some of these stages could be taken care of for me. Well, enter Hazel. Here's the setup once installed. 

1. Tell Hazel to Monitor your Downloads folder. 

Click the + button on the Folders window and navigate to the folder you wish to apply some rules to. As you can see, I have the Actions, Downloads, Desktop and Camera Uploads folders being monitored. 

2. Create your rules

Click the + button on the right hand Rules window this time. I have three rules applied to the Downloads folder. The first is a Weekly Cleanup rule, which takes all downloads that are over 7 days old and creates a new folder within my Downloads directory with all of these files in. Makes it a lot neater and tidier. The second two are the ones we will cover here. 

So working down the above screenshot, the Name of the rule is in the top box. This is just for your reference. The next box highlights the criteria that have to be met. Because I may or may not have more than one MasterCard (that's really my business!) I have specified two criteria which must both be met - this is represented by the ALL option in the drop down. This can change to ANY if you want to be more liberal with the options. The contents option means that the contents of the file will be scanned for the characters you have specified. 

If those contents are scanned and the criteria are met, then there are three things that will happen. 

1) It will move to the DEVONthink inbox. 

2) It will be given the tag "Credit Card" within the DEVONthink database

3) The file will be renamed automatically with the month that the file was downloaded and the year, followed by Tesco Credit Card Statement. (e.g. May 2014 - Tesco Credit Card Statement.pdf)

The following rule for Bank Account statements works on exactly the same principles however with slightly different qualifying criteria, based on the banking association I hold my accounts with. 

Hazel is immense. I'll post more rules over the coming months. I use it to automatically rename and file my photos, OCR my research documents and tag accordingly, empty my trash regularly,  organise my screenshots - I'm getting my money's worth out of it that's for sure. 

If you want to be kept updated with any Hazel posts, then subscribe to this RSS feed below or just keep checking back on the site. You can always email me for any other tips if you like.