Applescript + pdfpen for ocr on multiple files: move on after freeze

I’m using the following AppleScript to batch-process pdfs for ocr:

    tell application "Finder"
    	set target_folder to target of front Finder window
	repeat with i from 1 to count (every folder of target_folder)
		set current_folder to folder i of target_folder
		set current_batch to (document files of entire contents of current_folder whose name ends with "pdf")
		repeat with i from 1 to count (every item of current_batch)
			set current_pdf to item i of current_batch
			tell application "PDFpen"
				open current_pdf as alias
				tell document 1
					repeat while performing ocr
						delay 1
					end repeat
					delay 1
					close with saving
				end tell
			end tell
		end repeat
	end repeat
    end tell

While the script is perfectly functional, I have the following problem. After processing a number of files (say, between 10 and 50), pdfpen sometimes freezes during the ocr (progress-bar stops close to the end). The only way out is to halt the AppleScript and then ForceQuit pdfpen. Afterwards, I can restart where I ended, and the pdf on which pdfpen froze is not processed correctly. Conclusion: the freezing is independent of the pdf itself.

Is there a way to:

  1. make AppleScript notice that pdfpen froze,
  2. forcequit pdfpen
  3. and then restart the process with the last unprocessed file

I have an idea of how I could deal with the last part by having the script keep track of its progress, and could probably achieve the second point with

do shell script "killall pdfpen"

but am totally lost when it comes to the first point. I’ve experimented with “timeout” declarations, but this doesn’t seem to make any difference.

Any suggestions on how to deal with this?

(I need to process more than 150 folders that contain each between 5 and 20 pdf-files, so I’d rather avoid doing the quitting and restarting manually)

(disclaimer: I initially posted this on SuperUser, but on reflection this seems to be a better place for this type of question)

Model: mbpro
AppleScript: 2.1.2
Browser: Safari 537.36
Operating System: Mac OS X (10.6)