'is busy' error?

I have been a happy user of FineReader Pro on my Mac for some time. I usually batch process a number of files I have in DevonThink, usually between 10 and 50 at a time, using an Applescript (included below). Previously, FineReader Pro would process all of these seamlessly. Now, the process quits after just a few files, and I have to continuously restart it.

Just recently, I started receiving an error message, which stops the batch processing:

FineReader got an error: Could not execute the script because FineReader is busy processing a document. You can use the is busy command to determine FineReader’s state.

I have searched Google, without finding a good solution.

The script I am using is:

tell application “DEVONthink Pro”
set theSelection to the selection
repeat with theRecord in theSelection
set thepath to path of item 1 of theRecord
tell application “FineReader”
repeat until not (is busy)
end repeat
– add ocr text layer underneath and compress
export to pdf thepath from file thepath export mode text under image with use mrc

		-- uncomment next line if you want text to be on top of image. Works well if scan is good quality
		-- export to pdf thepath from file thepath export mode text over image with use mrc without keep pictures
	end tell
end repeat

end tell


Perhaps this is related to my recent update to Mojave?

Or is there an error in the script?

Thanks!

Hi.

I don’t have either DEVONthink Pro or FineReader, but from the point of view of script design, I’d be inclined to keep the two applications’ ‘tell’ statements separate and not to make FineReader have to reply to a continuous stream of ‘is busy’ queries while it’s trying to carry out the task it’s been set.

It is possible that you’ll need to grant permission for the application running the script to control DEVONthink Pro and FineReader the first time it tries to do so in Mojave, but the system should explicitly ask if that’s what you want to do.

tell application "DEVONthink Pro" to set theSelection to the selection

repeat with theRecord in theSelection
	tell application "DEVONthink Pro" set thepath to path of item 1 of theRecord

	tell application "FineReader"
		-- add ocr text layer underneath and compress
		export to pdf thepath from file thepath export mode text under image with use mrc
		repeat while (is busy)
			-- Allow FineReader some breaks between answering 'is busy' queries.
			delay 0.5
		end repeat
            
		-- uncomment next line if you want text to be on top of image. Works well if scan is good quality
		-- export to pdf thepath from file thepath export mode text over image with use mrc without keep pictures
		-- repeat while (is busy)
		--	delay 0.5
		-- end repeat
	end tell
end repeat

Hi, Nigel-

I greatly appreciate your advice from a few months ago. I have unfortunately not been able to solve this by myself.

I just copied and pasted your suggestion, but when I tried to compile, I got the error message,

“Expected end of line but found “set”.”

The highlight pointed to the word ‘set’ in the command, ‘repeat with theRecord in theSelection
tell application “DEVONthink Pro” set thepath to path of item 1 of theRecord’

I tried to modify the script a number of times until it would compile, ended up with:

tell application "DEVONthink Pro"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set thepath to path of item 1 of theRecord
		
		tell application "FineReader"
			-- add ocr text layer underneath and compress
			export to pdf thepath from file thepath export mode text under image with use mrc
			repeat while (is busy)
				-- Allow FineReader some breaks between answering 'is busy' queries.
				delay 0.5
			end repeat
			
			-- uncomment next line if you want text to be on top of image. Works well if scan is good quality
			-- export to pdf thepath from file thepath export mode text over image with use mrc without keep pictures
			-- repeat while (is busy)
			--    delay 0.5
			-- end repeat
		end tell
	end repeat
end tell

At this point, I compiled, then ran the script on a few files, and got the same original error message:

error “FineReader got an error: Could not execute the script because FineReader is busy processing a document. You can use the is busy command to determine FineReader’s state.” number 5.40094521E+8

I realize you don’t have the FineReader program, but perhaps you could point me in the right direction so I could search to get some clues.

Thanks again!

It looks to me like Nigel’s script was missing a “to.”

Since we don’t have the applications, Nigel would be unable to compile and be informed of even minor typos.

Please try:


tell application "DEVONthink Pro" to set theSelection to the selection

repeat with theRecord in theSelection
	tell application "DEVONthink Pro" to set thepath to path of item 1 of theRecord -- "to" added to this line

	tell application "FineReader"
		-- add ocr text layer underneath and compress
		export to pdf thepath from file thepath export mode text under image with use mrc
		repeat while (is busy)
			-- Allow FineReader some breaks between answering 'is busy' queries.
			delay 0.5
		end repeat
            
		-- uncomment next line if you want text to be on top of image. Works well if scan is good quality
		-- export to pdf thepath from file thepath export mode text over image with use mrc without keep pictures
		-- repeat while (is busy)
		--	delay 0.5
		-- end repeat
	end tell
end repeat



Oops! Many apologies, sawxray. I should have seen that. I must be getting older than I thought. :expressionless: Thanks for spotting the omission, t.spoon.

I see I’ve also moved the is busy repeat to after the export (or is it export to pdf?) command on the assumption that it waits for the command to complete and that it doesn’t matter either way in the context of the main repeat. But it may be worth trying with the inner repeat back in front of the export command so that even the first export isn’t attempted before FineReader’s ready.

I’ve just been looking at FineReader’s Web site. It urges users to update to the latest version that’ll run on their systems in order to avoid incompatibilities and known bugs. There’s a tutorial on how to use Automator with FineReader (https://support.abbyy.com/hc/en-us/articles/115005902149, but nothing about AppleScript apart a hint that FineReader supports it.

It’s interesting that your error message says “Could not execute the script…”. Is the script being run from a menu in FineReader, or is it run from outside? Does it work when there’s only one file to process, or does it fail even then?

I presume you’ve looked at FineReader’s scripting dictionary in Script Editor (or Script Debugger). Does is busy definitely return a boolean? It looks as if it should, but does the dictionary entry explicitly say so? Also, following a thought of my own inspired by the Automator tutorial, would it be possible to post the full dictionary entry for export (or export to pdf, if that’s what it’s called) here? If it’s possible to pass a list of files to process, there may not be any need for a repeat, apart from a vanilla AppleScript one to convert the paths to aliases. Just a thought.

If your original script used to work but stopped doing so after a system upgrade, updating FineReader is the first thing to try.

Thank you both again for contributing.

I have tried the latest script from t. spoon, and then made my feeble attempts at editing and finding the issue, without luck.

Going back to that script, I get the ‘Script failed…’ with the following error message:

Error Number: 540094521

FineReader got an error: Could not execute the script because FineReader is busy processing a document. You can use the is busy command to determine FineReader’s state.

Any thoughts on what I might next try?

I used a try block to also catch the busy error

tell application "DEVONthink Pro" to set theSelection to the selection

repeat with theRecord in theSelection
	tell application "DEVONthink Pro" to set thepath to path of item 1 of theRecord -- "to" added to this line

	tell application "FineReader"
		-- add ocr text layer underneath and compress
		export to pdf thepath from file thepath export mode text under image with use mrc
		set flag to false
		repeat 100 times
			try
				if not (is busy) then
					set flag to true
					exit repeat
				end if
			-- Allow FineReader some breaks between answering 'is busy' queries.
			end try
			delay 0.5
		end repeat
		(* uncomment next section if you want text to be on top of image. Works well if scan is good quality
		if flag then 
			export to pdf thepath from file thepath export mode text over image with use mrc without keep pictures
			repeat 100 times
				try
					if not (is busy) then exit repeat
					-- Allow FineReader some breaks between answering 'is busy' queries.
				end try
				delay 0.5
			end repeat
		end if
		*)
	end tell
end repeat

FWIW, I have finereader 12 (non-sandboxed).

Once upon a time, their web site had several example applescripts on it but they took them all down.

They used the busy command inside a double handler rather than in the main script, like so:

WaitWhileBusy()

tell application "FineReader"
	export to pdf toFile ¬
		ocr languages enum langList ¬
		saving type saveType ¬
		export mode exportMode ¬
		keep page numbers headers and footers keepPageNumberHeadersAndFootersBoolean ¬
		page size pageSizePageSizeEnum ¬
		keep pictures keepImageBoolean ¬
		image quality imageOptionsImageQualityEnum ¬
		keep text and background colors keepTextAndBackgroundColorsBoolean ¬
		use mrc useMrcBoolean
end tell


on WaitWhileBusy()
	repeat while IsMainApplicationBusy()
	end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
	tell application "FineReader"
		set resultBoolean to is busy
	end tell
	return resultBoolean
end IsMainApplicationBusy

I vaguely recall them stating that it was more reliable this way but I don’t recall the exact words they used. Note that the variables in the export command would all be set earlier in the script.


Here is a snippet from the dictionary which includes three commands which test for state and may be useful here.

As an aside, they produce two other versions. Devonthink Pro has a limited version built in and the commands are accessed within devonthink. Typically, it focuses on importing documents into devonthink (and using finereader to provide OCR for images).

There is also a limited version that is —I think— included with some scanners and which has a different dictionary.

Finally, the regular version comes in App Store (sandboxed) and self-installed (non-sandboxed, purchased from site). These are essentially the same but the sandboxed version has some quirks relating to security — an issue which affects some other apps and applescript.

has document

has document (verb) Determines whether a document is open in FineReader. (from the finereader suite)

FUNCTION SYNTAX
set theResult to has document

RESULT
boolean

is busy

is busy (verb) Determines whether FineReader is currently processing a document. FineReader will not accept any commands while the current document is being processed. (from the finereader suite)

FUNCTION SYNTAX
set theResult to is busy

RESULT
boolean

is finereader controller active

is finereader controller active (verb)Returns Yes if FineReader is running and ready. (from the finereader suite)

FUNCTION SYNTAX
set theResult to is finereader controller active

RESULT
boolean