Immediately ocr pdf file after copy to folder


I use script for ocr (non ocr) pdf file. The script makes 1) keep original file 2) save new file (OCR) with the name ORIGINALNAME_ocr.pdf. Script is below.

My wish is have folder on desktop and immediately if I copy pdf file to this folder, pdf will be ocr like the script makes - keep original file 2) save new file originalname_ocr.pdf. BUT If there is originalname.pdf and originalname_ocr.pdf script will do nothing.

How I can set it please?

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

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

Please use three backticks before an after your code like so
code goes here
That makes sure it is highlighted correctly, can be copy/pasted and possibly directly run in Script Editor.

Also, your question (or variants of it) has been asked very, very often here (and answered, too). I suggest you use the search function here and check the corresponding threads.

As to your code: It is advisable to reduce it to the bare minimum – that makes it faster to read and easier to understand. So, a progress indicator is nice, but distracting from the main task. The same holds for the try block, and set newName to newName is irritating.

Personally, I don’t see the point in keeping the non-OCR file and fiddling around with all these naming conventions. It seems overly complicated to me – if you absolutely need to keep the original, just set a tag on it after OCR’ing and skip all files where this tag is set in your script or smart rule.

While your attempt is admirable, this is not the advocated approach. See…

My needs are:

I receive a lot of non ocr pdf file thru day. I need to ocr it and copy together with original (non ocr) file to special folder of every project.

Now I copy every file to folder - start smart rule with script and copy to special folder. My idea is copy all non ocr file to one folder - the script should ocr it automatically - and in the end of workday I could copy everything to special folders = saving time :slight_smile:

Usage of parent 1 as a destination is actually discouraged, the recently added location group property is recommended instead.