Smart rule, OCR

Is there away to import multiple files in Inbox and then OCR them with smart rule?

Have a smart rule that OCR files on import then moves it to a specific location, works fine but only problem is that when I import multiple files just the first imported file is OCRd

Perhaps you could post a screenshot of the smart rule and state how you import the files to inbox. That may help to help you. Thanks :slight_smile:

1 Like

This rule works for me when importing multiple files by drag and drop, File > Import, or through the Sorter into the inbox, or any group in any open database

Screenshot_2020-10-28 09.45.13_cxuRGK

1 Like

Here is the smart rule.

I have Hazel.
Any PDF file in “download” Hazel moves it to DevonThink Folder (Finder) /DevonThink’s Inbox.

Again this smart rule works fine for the first PDF only, but not the rest when importing multiple pdf files.

I have an extra step “move to” not sure if thats he issue

I think what is happening is that the “on import” trigger is only being triggered once (because the documents all arrive at the same time); smart rules don’t batch process, I don’t think, so your rule would only work if the documents arrived one after the other (like when scanning).
The solution would be a script in your rule, instead of the current actions in the rule. I’ve just moved several items to inbox via Finder, and this short script correctly displayed the number of items, so OCR and move to folder via script would work.

on performSmartRule(theRecords)	
	tell application id "DNtp"
		set a to 0
		repeat with theRecord in theRecords
			set a to a + 1
		end repeat
		display dialog a
	end tell	
end performSmartRule

If you’ve not scripted DT before, I’ll post more later.

Having said all that, I’m not completely sure that is the reason the smart rule isn’t working. If they do batch process, then for sure your notification would display after each and every file, rather than at the end. Anyway, whatever the reason, the script will work, so that’s the way to go unless anybody else has an idea?

this works for me:

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			set workedFiles to 0
			set theFolder to get record at "/Unit 1,2" in database "NAMEofYOURdatabase" -- use name of the database containing group "Unit 1,2", and if "Unit 1,2" is a subgroup of a group then adjust the path accordingly
			repeat with theRecord in theRecords
				set theFile to convert image record theRecord
				move record theFile to theFolder
				set thisDatabase to the database of theRecord
				set unread of theRecord to 0
				move record theRecord to trash group of thisDatabase
				set workedFiles to workedFiles + 1
			end repeat
			set theDialog to "OCRd and moved " & workedFiles & " documents"
			display notification theDialog with title "Making life easier"
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end performSmartRule

Keep the conditions of your smart rule, adding the script (embedded) as the only action. You may want to finish the smart rule with a “Cancel” action.

@cgrunenberg Criss, when I run this script the info area at the bottom left of the main window only displays information whilst adding/OCRing the first document, but then closes and displays no further information (such as “adding document”) for subsequent documents. Is that a bug?

I just successfully tried both this script and the above smart rule by @Hens. But the smart rule should indeed only display the notification after processing all records if the text is not record specific, I’ll change this.

1 Like

Two things:

  • the OP was not successful with the smart rule - it only OCRd the first record in the batch; when you say you successfully tried the rule, does that mean it OCRd all the files you’d imported in one go? (I simulated his approach by copying several documents and pasting them all at once in Finder to inbox) If so, I wonder what the difference is?

  • when using the script, we’re you able to reproduce the issue I noted with the info field in the bottom left of the main window?

1 Like

In both cases everything worked as expected - all files were processed, the Activity pane/window showed the correct stuff. But I don’t use Hazel and just imported few PDFs without text via drag & drop.

You did Drag & Drop directly to the inbox, rather than to the Inbox in the Finder? I pasted the files to the Inbox in the Finder rather than dropping directly into the inbox in DT, because I assume that simulates the problem described by the OP better (I don’t have hazel either)

Works fine too but I’m using the latest internal build although it doesn’t fix anything related to smart rules.

:man_shrugging:t3: Strange, thanks for trying it out. @Hens I can’t explain why your rule works for Criss but not for you… if my script (or something similar) works for you then what shalls, otherwise we’ll have to dig deeper. Let us know :slight_smile:

1 Like

I couldn’t reproduce this here either…

This processed all three files I dropped in my Downloads folder.

1 Like

Jim, could you add the notification action to your rule please? It’s the only obvious difference between your rule and the OPs. After that I’m stumped. Thanks for trying (I don’t have Hazel).

1 Like

Thanks. Last thing: I note your rule searches in “Global Inbox”; on DT 3.5.2 rules which I create and which search in the global inbox display “Inbox” for Search in rather than “Global Inbox”; it seems to be the same for the OP too. Are you running a super secret COVID-free internal version too, or is the difference something to do with localisation?

1 Like

:rofl:

It’s just the name of the Inbox. That’s its proper name therefore if it wasn’t Global Inbox, I’d rename it to be so.
Note: DEVONthink To Go uses Global Inbox as the proper name as well.

PS: Yes, you can rename the Global Inbox but we don’t advocate it, especially as it could be confusing to the users as well as support.

2 Likes

Thanks for your help.

I tried this script and it didnt work. I target the name of the folder “Unit 1,2” it was a subfolder but to make it easier just brought it up to the main window of the database and of course I targeted the name of the database. But it didnt work. Both PDF files remained in the Global Inbox and no OCRd.

here is what I did.