AppleScript, Hazel and Abbyy FineReader

Discussion in 'Mac Programming' started by dragonladygb, Sep 3, 2015.

  1. dragonladygb macrumors newbie

    Nov 7, 2014
    I am using Hazel to run an AppleScript to execute Abbyy FineReader 12 to OCR files automatically. I am an AppleScript newbie.

    I have 3 problems/questions:

    1) I expect there is a way to detect if Abbyy FineReader executed successfully or had an error but I am not sure how to do it.

    2) When FineReader runs, the date added and date created are set to the current date/time along with Date Last Opened and Date Last Modified. Is there a way to maintain the date added and date created as happens when I run the application manually?

    3) What I really want to do, is run Fine Reader only if a new pdf is added, or if a pdf is modified by other than FineReader. Any ideas on how to accomplish that?

    My apple script (which was found on the Noodlesoft Hazel forum) is run using Hazel.

    on hazelProcessFile(theFile)
        using terms from application "FineReader"
            set langList to {English}
            set saveType to single file
            set exportmodepdflayout to "text under the page image"
            set keepPageNumberHeadersAndFootersBoolean to yes
            set keepImageBoolean to yes
            set imageOptionsImageQualityEnum to high quality
            set usemrcboolean to no
            set makepdfaboolean to yes
            set pageSizePageSizeEnum to automatic
            set increasePaperSizeToFitContentBoolean to yes
        end using terms from
        tell application "FineReader"
            export to pdf theFile from file theFile
        end tell
    end hazelProcessFile
    on WaitWhileBusy()
        repeat while IsMainApplicationBusy()
            delay 10
        end repeat
    end WaitWhileBusy
    on IsMainApplicationBusy()
        tell application "FineReader"
            set resultBoolean to is busy
        end tell
        return resultBoolean
    end IsMainApplicationBusy
  2. superscape macrumors 6502a


    Feb 12, 2008
    East Riding of Yorkshire, UK

    I'm not familiar with Hazel or FineReader so my advice is going to be rather general. I can't help you with question 2, but as far as question 1 goes... You do very basic testing for an error like this:

       set theAnswer to 10 + "foo"
    on error theError
       display alert "Ooops!" message theError
    end try
    In my example, the second line will always fail since you can't add text to a number. An error message will be generated and saved in the "theError" variable. In my code I choose to display the error to the user, but you can do as you see fit. For more detailed and advanced methods, take a look at this:

    It's possible that FineReader may return *something* useful as a result of the export command (e.g. a true or false depending on whether it succeeded or not). You'd need to look at the scripting dictionary to find out.

    As far as question 3 goes, I assume you mean you want to run your script when a file is added to a folder? If so then take a look at Folder Actions. Probably the easiest way is to make them through Automator.

    Hope that's of some help!
  3. kai-uwe-heinz macrumors newbie

    Sep 12, 2015
    I had the same intention. This is what worked best for me: I use the "hot folder" included in Abbyy 12. All files in a specific "hot" folder are OCR'ed according to my presets. Hope that helps. GBU

Share This Page