I searched the Automation forum with a few different queries but could not find an existing script. Is it possible to script this process? Take as input a jpeg image from the system clipboard, apply OCR conversion via DTP, set the clipboard with the returned text. For simplicity, I’m hopeful that temporary objects won’t need to be created in the DTP database. If possible, I would prefer that DTP simply remain in the background.
Why? I occasionally have a PDF with an existing text layer but the text selection is defective – discontiguous parts of the document are selected when I drag. Sometimes the desired part cannot be selected no matter how I tinker with the selection range. But in these cases it is overkill to OCR the entire PDF. Instead, it would be helpful to screenshot the offending text block (I’m using SnagIt) and then convert it to text, ready for pasting elsewhere. It is too slow to manually switch to DTP, create a new entry with New With Clipboard, then OCR, and so forth.
Create a folder inside DT. Then a Smart Rule that will OCR anything dropped in that folder. I cannot give you more precise details but remember someone posted or explained here how to do this.
In Snagit Preferences > Outputs add the path of the indexed group
This way you could get the text copied without activating DEVONthink.
Caution:
This script moves everything from the Smart Rule’s target group into the trash.
-- OCR, copy text and move to trash
on performSmartRule(theRecords)
tell application id "DNtp"
try
repeat with thisRecord in theRecords
set thisPath to (path of thisRecord)
set thisGroup to (parent 1 of thisRecord)
set newRecord to ocr file thisPath to thisGroup
set newRecord_Text to plain text of newRecord
set the clipboard to newRecord_Text
display notification "Copied"
move record thisRecord to trash group of database of thisRecord
move record newRecord to trash group of database of newRecord
end repeat
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