1

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"
            activate
            open current_pdf as alias
            tell document 1
                ocr
                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:

  • make AppleScript notice that pdfpen froze,
  • forcequit pdfpen
  • 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)

1
  • Just to say: I unfortunately don't have the answer to the problem, but I am experiencing the same issue. I did have a workaround involving killing the PDFPenOCR process when it timed out, but this stopped working with PDFPen v6.3. I'll post back here if/when I get an answer from Smile's support ...
    – KenD
    Jul 6, 2014 at 18:58

0

You must log in to answer this question.

Browse other questions tagged .