problem..

using terms from application "DEVONthink Pro"
using terms from application "DEVONthink Pro"
	tell application "DEVONthink Pro"
		activate
		set this_selection to the selection
		repeat with this_record in this_selection
			try
				if (plain text of this_record is "") and (type of this_record is not group) then
					set old_date to modification date of this_record
					display dialog ("going to convert image")
					set converted_record to convert image record this_record
					display dialog ("setting date...")
					set the modification date of converted_record to old_date
					display dialog (modification date of converted_record as string)
				end if
			on error error_message number error_number
				display(error_message)
			end try
		end repeat
	end tell
end using terms from


Could someone explain why when this script is run from Script menu it does not set modification time, but when run from edit editor it sets the modification time just fine? It is driving me crazy? I’ve made sure it is saved, saved to a new file name, updated the script menu items, restarted the application… It’s very strange!!

The display dialog “setting date” is actually never shown when run from within application. It’s almost like the script dies after doing the image convert and adding that record to database.

Any suggestions?

-jr

Replace…

display(error_message)

…with…

display dialog (error_message)

…and you should at least get an appropriate error message.

Thanks… Applescript still a bit new to me…

Ok, says “AppleEvent timed out” when running from application…

-jr

Replacing…

set converted_record to convert image record this_record

…with…

set converted_record to convert image record this_record

with timeout of 120 seconds
set converted_record to convert image record this_record
end

…should fix the timeout.

No, that didn’t help. I even tried moving the timeout around the entire thing. It is almost like IRIS is timing out coming up… because now I am not even seeing the IRIS dialog pop up.

But again, running this from script editor works 100% fine…

-jr

The timeout dialog is almost instant. Comes up right when running script and the “OCR Status” dialog says “Opening …filename…”

-jr

This is the script I use in the Convert\ Selection\ using\ OCR.workflow example:

on run {input, parameters}
	local output, aRecord
	
	set output to {}
	tell application "DEVONthink Pro"
		repeat with aRecord in input
			with timeout of 3600 seconds
				-- New record is created in same group as aRecord by default
				try
					set newRecord to convert image record aRecord
					set output to output & {aRecord}
				on error errMsg number 9104
					-- Possible errors that are returned (numbers subject to change):
					--    kIRISProcessingError = 1003
					--    kIRISMaxOCRPageExceededError = 9100
					--    kIRISNoOrEmptyFileError = 9101
					--    kNoImageRecordError = 9102
					--    kExportImageRecordError = 9103
					--    kPDFImportFailedError = 9104
					--    kUnknownExceptionError = 9105
					log message errMsg info (name of aRecord) & ": Check “~/Library/Caches/DEVONthink Pro/OCR” for files that weren't imported"
				end try
			end timeout
		end repeat
	end tell
	-- Returns successfully converted records (to be moved aside)
	return output
end run

Thanks, but that doesn’t help as the problem only occurs when running the script from within DT.

Here is the simplest script I could come up with which replicates the problem on multiple machines. Can someone else please confirm whether or not it is reproducible in their environment?


using terms from application "DEVONthink Pro"
	tell application "DEVONthink Pro"
		activate
		try
			with timeout of 3600 seconds
				set the_selection to selection
				set this_record to item 1 of the_selection
				set converted_record to convert image record this_record
			end timeout
		on error error_message number error_number
			display dialog (error_message)
		end try
	end tell
end using terms from


Your script works fine over here. Try to clean your LaunchServices database and check if it works better afterwards. I’ve had strange AppleScript problems before that got fixed by this simple action. Any cache cleaning tool will do the job.

I’ve used maintenance to do as you suggest and clear the launchservices database and still get the same result. What should I do at this point?

It does the same thing for me on two different machines.

What else can I try?

I really need to get this resolved as I have a bunch of PDFs I need OCRd and I want to do it via a script to keep modification time in tact. It seems anything which executes the convert to image command in the script isn’t going to work.

-jr

Also, what would cause this script to work perfectly fun when running from the Script Editor, but error out when running in DT?

-jr

I’ve done everything suggested and even tried to create a new user to start with a fresh profile, fresh DT database and get the same results…

-jr

I have no idea, maybe Christian has a better idea?

Please send both the script and the document you’re trying to OCR to our support address and we’ll check this over here.

Christian, the actual document being OCR’d doesn’t matter. It occurs on each document. I’ve tried it on .JPG documents, or PDFs without text… It occurs with a blank database or my database with 1.5G worth of documents. It occurs on a new user profile, or my existing user profile. The script I used is the one posted in this thread. Nothing more then OCR’ing the selected document. Very simple stuff.

The funny thing is that script works perfect when running from script editor.

Would be happy to provide access to my machine to show you examples of what is happening so that we can get this resolved.

Thanks!

-jr

You are correct, if you execute this script inside DT it fails. And I have no idea why. While we’re investigating, there is a workaround (as usual). You can put this script inside an Automator workflow and put that workflow in the Script menu by replacing it with your current script. Since Automator runs in a separate process, it won’t trigger the problem.

Perfect. Thanks, I look forward to the fix. As long as we work towards a solution I am happy. Thanks for creating such an awesome product!

-jr

Can you try this again with 2.0pb3? I just looked at it and it seems to work now (admittedly with the upcoming version of the OCR plugin but nothing changed in the run model). If not, then try with 2.0pb4 when it comes out.

Will do and report back.

-jr