Best practice for handling app timeouts?

Hi --
I'm trying to automate the processing of a large number of PDF files using PDFPenPro. On occasion one of the PDF files appears corrupt, and the AppleScript that is automating PDFPenPro times out because a dialog box is visible in the app ("This file appears to be corrupt..." etc). Unfortunately this then appears to stall out subsequent processing of valid PDFs.
Is there a recommended best practice for defining, detecting and handling exception cases like this in Hazel? I know how to recognize the situation in AppleScript using something like this (using Preview instead of PDFPenPro):
But I'm not sure how to recover elegantly in the error handling code. I'd like to just e.g. move this file to a separate folder for future review, but then somehow dismiss the error dialog box in the app and/or quit the app so Hazel processing can continue. Is there a best practice or design pattern for doing this in Hazel automation?
Thanks,
Ramon
I'm trying to automate the processing of a large number of PDF files using PDFPenPro. On occasion one of the PDF files appears corrupt, and the AppleScript that is automating PDFPenPro times out because a dialog box is visible in the app ("This file appears to be corrupt..." etc). Unfortunately this then appears to stall out subsequent processing of valid PDFs.
Is there a recommended best practice for defining, detecting and handling exception cases like this in Hazel? I know how to recognize the situation in AppleScript using something like this (using Preview instead of PDFPenPro):
- Code: Select all
try
tell application "Preview"
with timeout of 5 seconds
open file "Harddisk:Users:username:Documents:mypdfs:example.pdf"
end timeout
quit
end tell
on error errmsg number errNum
if errNum is -1728 then
display dialog "Hey, that file doesn't exist!" buttons {"Doh!"}
else
-- how should I recover from the error here
display dialog errmsg buttons {"Oops"}
end if
end try
But I'm not sure how to recover elegantly in the error handling code. I'd like to just e.g. move this file to a separate folder for future review, but then somehow dismiss the error dialog box in the app and/or quit the app so Hazel processing can continue. Is there a best practice or design pattern for doing this in Hazel automation?
Thanks,
Ramon