DT3 3.5.2: OCR weirdness

Just installed Version 3.5.2 (and also, implicitly, a new (?) version of Abby’s OCR software). Imported an already OCR’d document (by PDFPenPro) into DT3. It’s shown as “PDF-Document”, whereas it should be “PDF + Text”. Can’t run OCR in DT on it, all menu options (context menu and “data” menu) concerning OCR are grayed out.
Looked at the text inspector (is that the right word?) and it seems that it sees a lot of words in this PDF.

Tried with other PDFs (OCR’d and not) and the both menus offer to OCR them to searchable PDF.

Does it work after reimporting the document again? Was anything logged to Windows > Log?

Tried again with the complete workflow (save mail attachment to Downloads, have Hazel run PDFPen, change file name and open in DT3) and got

which doesn’t tell me much :wink: Hazel moves the file to the trash after opening it in DT3. If I open this file (after having moved it to Desktop) in DT3, it looks ok.
Could this be a race condition, i.e. the file’s already moved to the trash by Hazel before DT3 gets a chance to import it? (Although that worked ok before, but that’s what they always say :wink:

It’s possible that Hazel removes the file before it’s indexed, this would cause such an error message and a document of an unknown type internally (which can therefore not be OCRed). Did you try to reimport the document on your own?

Yes, as I said: I moved it from the trash to the desktop (DT wouldn’t open it from the trash) and then opened it in DT. Looked ok. However, on the first try, no document at all was imported, not even of an unkown type.
I’ll have an eye on it.

After adding a 2 second delay to the hazel action, it worked ok again.

Rant: It’s not that I mind asynchronous execution. I just hate it if there’s no framework for it, like callbacks or promises. This seems to be a problem of AppleScript and possibly other Mac scripting languages. They let us believe to run their methods sequentially, but once in a while they don’t.

Was the file imported via AppleScript?


  • From Hazel, I use their action “open in”
  • In the other cases, I just used “open with” from the finder.

I suppose that Hazel uses the exposed open method of the other application (DT, in this case) and that there’s no mechanism for it to actually know that the file has successfully been opened. Since the race condition: There’s no way to wait for the action to complete, so the file is already in the trash before DT has had it imported.
I suppose I could change that behavior by using an AppleScript from within Hazel to import the file into DT.

That’s probably the best solution as the “import” command of AppleScript works synchronously.

And since I already have a script that can import from Hazel to a DT3 group, taking a parameter to determine the group … That’s actually a lot better.

Hmmm… in all of my Hazel rules, I import files I have treated with Hazel into DT3 by moving them into the “Inbox“ magic directory, and this never created any issues for me.

No need for any pesky AppleScript, a simple move like this works for me:

Is there anything that I am missing here @chrillek? Is there any reason for you not to use this same way to import files into DT3?

Bye, Luca

1 Like

Yes. The sequence in my case was

  • open in Dt
  • move to trash

I do not use DT’s finder integration. And the

permits me to move the files directly to the relevant group. Nice for account statements, for example, where I have a group for each account. It’s a Javascript in my case, btw.

1 Like

Got it.

Have you used one of the default AppleScript scripts provided with DT3, or you are using something you have crafted yourself?

As you can imagine, I am a lot less sophisticated in my knowledge of DT3, and any trick to improve the way I handle file input into DT3 via Hazel is golden for me.

Many thanks, Luca

Ciao Luca,

As I said, it’s a JavaScript script, and yes, it is hand crafted. Sollid german engineeren, so to say :wink: .
It runs in Hazel and looks like this:

function hazelProcessFile(theFile, inputAttributes) {
  var groups = { 
           "account1": ["database1", "UBI"],
           "account2": ["database2",  "Intesa"],
	       "account3": ["database3",  "Banca Popolare 1"],
	       "account4": ["database3", "Banca Popolare 2"],
	       "tag1" : ["database2", "Expenses"],
	       "tag2" : ["database2", "Expenses"],
  var app = Application('DEVONthink 3');
  app.includeStandardAdditions = true;
  var target = inputAttributes[0];
  var dbName = groups[target][0];
  var groupName = groups[target][1];
  var db = getDBByName(app, dbName);
  var g = app.search("name:" + groupName + " kind:group kind:!tag", {in: db});
  app.import(theFile.toString(),  {to: g[0]});

function getDBByName(app, dbName) {
  return (app.databases.whose({name: dbName})[0]).root();

As you can see, I pass not only the current file (first parameter) to the script, but also a second parameter. This one depends on the file: if it’s an account statement, it is the account number. Otherwise, it is the tag set by Hazel previously, depending on the kind of receipt.

The script uses the data structure at the top to determine the DT database and group where the file is going to be added to. That permits me to use the same script in different Hazel tasks - they all use their own mechanisms to rename the file, extract information (to set the tag, for example) etc. In the end, they call this script with the relevant information and in the end, the file arrives in the correct group in DT.

I’m sure that this could be achieved with AppleScript as well. I’m just not as comfortable with it as with JavaScript.

1 Like

@chrillek Vielen Dank!

It makes no difference to me if it’s JS or AppleScript, I was just curious to see the logic. I can definitely understand JS better than AppleScript!

Funny to see names of Italian banks in the script… an Italian living in the French-speaking part of Switzerland wonders if it was done on purpose for me! :smiley:

I will definitely keep this great example as a reference the more I go into automating tasks on Hazel+DT3.

Ciao, Luca

Certo. Tout à fait. I forgot about you living in Switzerland, then I’d have used UBS and Credit Suisse en lieu de UBI and Intesa.

I tend to do as much in one place as I can. I.e., if I start out with Hazel, I try to do everything (renaming, tagging etc) there, before I move the files to DT. That’s a matter of taste, of course.

1 Like

ah! We’re big on cantonal banks here, so it would be BCV in the case of my canton of Vaud! :wink:

+1 on this. I like Hazel a lot and Paul has always been a great help for any issue I had over the last 10 years or so I have been using his product. If I can do things in Hazel, plus some scripting, then I am a happy bunny!

And you’ve also taught me how to reply with inline quotes on this forum, something I did not know how to do! :pray:t2::muscle:t2::clap:t2:

Ciao, Luca

A seriously multilingual German with bank accounts throughout Italy and an intricate knowledge of JS. I love this forum :smiley: