scripting batch submit - confused. thanks.

Hi -

This is one of my first attempts with Applescript and I’ve had the better part of a couple of days searching as I go along, pickup up the syntax and particulars. I’m lost and have gotten pretty turned around - if anyone can straighten out this code a bit it would be immensely appreciated.

I’m using a ScanSnap S510M to do a pretty large volume of OCR work and attempting to set up a workflow that is as automated as I can get it. Most of the software provided with the scanner has some ability to help along but he tool that has given me the best final OCR accuracy has one large flaw: when it is passed a (PDF) file from the scanner software that does the first capture, it begins the OCR that takes much longer than the actual scan time. If a second document is passed to the program it stops and comes up with a dialog telling the user it is busy. There are no queues or watch folders.

Here’s what I have setup:

S510M SCANNER → DATA INTO “SCANMANAGER” APP THAT CREATES PDF AND SAVES TO “BATCH” FOLDER UNATTENDED → SCRIPT WATCHING FOLDER THAT FEEDS FILES ONE AT A TIME TO → FINEREADER OCR SOFTWARE THAT MUST SAVE BACK TO SAME FOLDER → SCRIPT WAITS FOR OUTPUT AND COPIES IT TO “PROCESSED” FOLDER

With this I can scan as fast as the hardware allows and the files collect in the batch folder. They are then processed at the rate the OCR software can work. I have tried folder actions but found they would run multiple instances and submit any second or third arriving files immediately. I ended up (trying to) create a script that I can launch manually at the start of work that uses “on idle” to watch the folder for activity. Here’s where I got:



property watch_folder : ""
property output_folder : ""
set watch_folder to (choose folder with prompt "Select watch folder:")
set output_folder to (choose folder with prompt "Select output folder:")

on idle
	tell application "Finder"
		set folder_items to every item in folder watch_folder
	end tell
	repeat with this_item in folder_items
		tell application "Finder" to open this_item using the application "FineReader"
		repeat until (do shell script "mdls " & quoted form of POSIX path of ((this_item) as string)) contains "ABBYY"
			delay 1
		end repeat
		tell application "Finder" to move this_item to output_folder
	end repeat
return 5
end idle

I’m not sure if that was the final version as I just ultimately got confused - there are issues with the class references and my syntax. I approached this a few other ways for my loops but always had issues at some point.

The repeat loop looking for “ABBYY” was tested seperately and works well as the file is not renamed after processing - the OCR software saves back to the same filename and the same folder. The input and output folders are not able to be specified within that software. So I ended up waiting until the file creator metadata changes after the OCR software (FineReader) saves back out the file. That part works well. My main thing is just properly defining the array of the folder contents and passing it along to be opened in the beginning (the opening app must be specified as it is not the default for a PDF).

The other problem I had was I could never define the paths correctly as strings and could only get things to work at all if I let the script record them from the “choose” finder action. I would prefer they are just hardcoded as they will remain constant for a long time.

Any help or ideas on the right way to approach this would be great. I’ve been at this too long and am a bit stuck.

Thank you.

Model: MacBook Pro
AppleScript: with 10.5
Browser: Firefox 2.0.0.13
Operating System: Mac OS X (10.5)

Hello Akamomo,

Thanks a lot for this script. I’m a beginner in Applescript and I’ve also spent a lot of time on finding a way to manage the FineReader OCR queue but my first solution did not work very well.

Here is what now works for me :


property watch_folder : "Macintosh HD:Users:azteny:Documents:WATCH_FOLDER:"
property output_folder : "Macintosh HD:Users:azteny:Documents:OUTPUT_FOLDER:"

on idle
	
	tell application "Finder"
		set folder_items to every item in folder watch_folder
	end tell
	
	repeat with this_item in folder_items
		tell application "FineReader for ScanSnap" to open (this_item as string)
		repeat until (do shell script "mdls " & quoted form of POSIX path of ((this_item) as string)) contains "ABBYY"
			delay 5
		end repeat
		tell application "Finder" to move this_item to output_folder
	end repeat
	
	return 10
	
end idle

I save this script as an application “sendFileToFineReader.app”. And for this application to automatically launch when a file is created in the watched folder, I create a folder script attached to it :


on adding folder items to this_folder
	tell application "Macintosh HD:Users:azteny:Documents:AUTOMATE:sendFileToFineReader.app" to activate
end adding folder items to

I hope this will help! If the application could automatically stop when there’d be no more files in the watched folder, that would be great!