Rename file after action (Smart Rules)


how is possible to rename new file after processing action via smart rules.

For example - smart rules - after OCR is created new OCRed file like originalname-1.pdf I want to automatically rename it to originalname_ocr.pdf

But there is no action like this on actions (smart rules). There is only change name but no change filename.


Within the constraints of the file system, changes made to the name of an item in DEVONthink are reflected in the file name in the file system (i.e., shown in Finder).

OCR function create new file originalfilename**-1**.pdf but I want to have every new ocr file originalfilename**_pdf**.pdf

Is it possible by the smart rules? How?


It is; but we need to start one step back - how are you triggering OCR?

Via smart rules - like on the pictures

Snímek obrazovky 2021-05-08 v 18.37.44

if instead of OCR to Searchable PDF you use the following script (embedded), I think what you are asking for should work (this is assuming I have understood you correctly); please test before using in on important files:

on performSmartRule(theRecords)
	tell application id "DNtp"
			show progress indicator "OCR" cancel button 1 steps count of theRecords
			repeat with theRecord in theRecords
				if cancelled progress then error number -128
				step progress indicator (name of theRecord) as string
				set theFile to path of theRecord
				set newName to name of theRecord
				set newName to newName & "_ocr"
				set newFile to ocr file theFile to parent 1 of theRecord type PDF document
				set name of newFile to newName
			end repeat
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		end try
		hide progress indicator
	end tell
end performSmartRule

Edit: this script uses a progress indicator. Whilst OCR opens its own progress indicator, canceling that will only cancel the current file. If the rule/script is run on a large number of (large) files, there would be no option to cancel all if the script didn’t integrate a second progress indicator. A trap for the unwary, so to speak.

Great ! It works perfect.

Only new_pdf file is very small (low quality). Is it possible to change DPI (resolution)?


I think the settings in the preferences are applied, regardless of how OCR is triggered.

The resolution can be set from 150 to 300 dpi. If for your test you used a file which already had a text layer or had previously been OCRd, the results may have been misleading. You might want to add a condition to your smart rule which says Word count is 0; that way your rule only acts on PDFs without a text layer.

Are you referring to indexed files?

Forgive my ignorance. But where do I find how to make a smart rule? Thank you

Have a look in the documentation. There’s a chapter on “Automation” that also explains smart rules.