Create PDF+Text OCR with AppleScript

Does anyone use AppleScript to create PDF+Text documents with OCR?
I have a problem with the following code. I can not get a PDF back from the command convert image. In DTPO 2 the script worked without error. Is there in DTP 3 changes in the AppleScript, in the forum and in the documentation I have not found anything about it?

tell application id "DNtp"
	try
		if type of thisItem is PDF document and word count of thisItem is 0 then
			with timeout of 60 seconds
				try
					set TrashItem to convert image record thisItem with waiting for reply
					move record TrashItem to (trash group of database of TrashItem)
				on error error_message number error_number
					if the error_number is 9104 then
						log message error_message info (name of thisItem)
						display alert error_message & return & "~/Library/Caches/DEVONthink Pro/OCR” for files that weren't imported" message error_message as warning
						error "Run OCR of " & name of thisItem
					else
						log message error_message info (name of thisItem)
						error "Run OCR of " & name of thisItem
					end if
				end try
			end timeout
		end if
		return thisItem
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Thanks for help

There is a separate ocr command in the dictionary.

@BLUEFROG Unfortunately I can not see your posting in the forum anymore but it worked for me. Thanks for your help without you, I would never have tried ocr command. I thought the work was the same.

If anyone still has the same problem, the following works for me

tell application id "DNtp"
	try
		if type of thisItem is PDF document and word count of thisItem is 0 then
			with timeout of 60 seconds
				try
					set TrashItem to thisItem
					set ItemPath to path of thisItem
					set thisItem to ocr file ItemPath with waiting for reply
					move record TrashItem to (trash group of database of TrashItem)
				on error error_message number error_number
					if the error_number is 9104 then
						log message error_message info (name of thisItem)
						display alert error_message & return & "~/Library/Caches/DEVONthink Pro/OCR” for files that weren't imported" message error_message as warning
						error "Run OCR of " & name of thisItem
					else
						log message error_message info (name of thisItem)
						error "Run OCR of " & name of thisItem
					end if
				end try
			end timeout
		end if
		return thisItem
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell
1 Like

Weird…
But glad to hear it!

I’ve undeleted the post (no idea who deleted it).