Abby FineReader now has Applescript but can't get it to work

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi,

Back in Nov 2014, Abbyy announced that their FineReader product is now applescriptable. See http://www.abbyy.com/news/ABBYY-FineReader-Pro-for-Mac-Now-Supports-Mac-OS-X-Native-Automation-Tools/

Their support also provided sample applescript code (see http://macscripter.net/viewtopic.php?id=43516) to control FineReader to automatically OCR - I had thought it would be relatively easy to modify it for Hazel but no...

Had struggled with this for 4 days but to no avail - I keep getting a error on "expected end but found no" at the WaitWhileBusy sub-routine. Please, what is wrong with this code so that I can use it as an embedded script within Hazel?

---

using terms from application "FineReader"
set langList to {English, German}
set saveType to single file
set retainLayoutWordLayout to as editable copy
set keepPageNumberHeadersAndFootersBoolean to yes
set keepLineBreaksAndHyphenationBoolean to yes
set keepPageBreaksBoolean to yes
set pageSizePageSizeEnum to automatic
set increasePaperSizeToFitContentBoolean to yes
set keepImageBoolean to yes
set imageOptionsImageQualityEnum to balanced quality
set keepTextAndBackgroundColorsBoolean to yes
set highlightUncertainSymbolsBoolean to yes
set keepPageNumbersBoolean to yes
end using terms from

WaitWhileBusy()

tell application "FineReader"
set hasdoc to has document
if hasdoc then
close document
end if
end tell

WaitWhileBusy()

tell application "FineReader"
set auto_read to auto read new pages false
end tell

tell application "Finder"
open theFile ¬
using application "FineReader"
end tell

delay 5

WaitWhileBusy()

tell application "FineReader"
export to pdf
end tell

WaitWhileBusy()

tell application "FineReader"
auto read new pages auto_read
close document
quit
end tell

on WaitWhileBusy()
repeat while IsMainApplicationBusy()
end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
tell application "FineReader"
set resultBoolean to is busy
end tell
return resultBoolean
end IsMainApplicationBusy
kaiwei
 
Posts: 5
Joined: Wed Feb 11, 2015 6:45 am

I suggest trying it out outside of Hazel as the problems aren't Hazel specific. Also, in the future, when posting code, it's probably best to use the code tags so that formatting is preserved. Otherwise, it's hard to read.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

For what it's worth, I fixed it. If anyone else has Abby FineReader with Applescript support, here it is. Note that you have to run this as an external applescript.

Code: Select all
on hazelProcessFile(theFile)
   
   using terms from application "FineReader"
      set langList to {English}
      set saveType to single file
      set exportmodepdflayout to "text over the page image"
      set keepPageNumberHeadersAndFootersBoolean to yes
      set keepImageBoolean to yes
      set imageOptionsImageQualityEnum to balanced 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
   
   WaitWhileBusy()
   
   tell application "FineReader"
      quit
   end tell
   
end hazelProcessFile

on WaitWhileBusy()
   repeat while IsMainApplicationBusy()
   end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
   tell application "FineReader"
      set resultBoolean to is busy
   end tell
   return resultBoolean
end IsMainApplicationBusy
kaiwei
 
Posts: 5
Joined: Wed Feb 11, 2015 6:45 am

Sorry for the bump!

First off, thanks for your AppleScript for use with Hazel and Abby Finereader Pro.

It seems to be working fine for me however it does have two flaws for my personal use, I was wondering if you or somebody else here could perhaps help me out with this.

I personally prevent Hazel from processing files again with a document tag and/or document label (color). Do you know the applescript for upon saving to add the tag "ocr" and label "yellow?" If I try and let Hazel do it, Hazel will tag the file but by the time Abby is done and saves the file it saves it without tags or labels.

Also it seems to save a new file all together where the date created is the current time, is there any way to preserve the original date created?

Thanks!
Dutchie
 
Posts: 1
Joined: Sat Nov 14, 2015 7:56 pm

Thanks for posting the script,

I'm trying it with FineReader Pro 12.1.4 and it's definitely doing something as the file size and date of the PDF changes.

I don't however seem to have an OCR layer being saved behind the text as they are when scanning from my ScanSnap (which is using ABBYY FineReader for ScanSnap).

Is anyone else getting this?

Thanks,

Mark.

kaiwei wrote:For what it's worth, I fixed it. If anyone else has Abby FineReader with Applescript support, here it is. Note that you have to run this as an external applescript.

Code: Select all
on hazelProcessFile(theFile)
   
   using terms from application "FineReader"
      set langList to {English}
      set saveType to single file
      set exportmodepdflayout to "text over the page image"
      set keepPageNumberHeadersAndFootersBoolean to yes
      set keepImageBoolean to yes
      set imageOptionsImageQualityEnum to balanced 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
   
   WaitWhileBusy()
   
   tell application "FineReader"
      quit
   end tell
   
end hazelProcessFile

on WaitWhileBusy()
   repeat while IsMainApplicationBusy()
   end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
   tell application "FineReader"
      set resultBoolean to is busy
   end tell
   return resultBoolean
end IsMainApplicationBusy
MacOCD
 
Posts: 44
Joined: Fri Sep 26, 2014 11:02 am

Unfortunately I could not get that script to work also.

Fine Reader does have a bunch of Automator scripts though (found within Automator). I created a folder action in Automator that is run when a document lands in my scanned folder. The finereader script opens the document and OCRs it.

Hope this helps
Chuggett
 
Posts: 30
Joined: Wed Mar 16, 2011 9:17 pm

What I found is that it is critical that Abby FineReader is complete after each step or when you send the next command you can get errors.

This is not the most elegant programming but I got it to work (it is my modification on an example at http://macscripter.net/viewtopic.php?id=43516

Code: Select all
on hazelProcessFile(theFile)
   
   set appLoc to "/Applications/FineReader.app"
   set ourApp to POSIX file appLoc
   
   using terms from application "FineReader"
      set langEnglish to {English}
      set imageQualityBalanced to balanced quality
      set pdfLayoutTextUnder to text under image
      set saveSettingsSingleFile to single file
   end using terms from
   
   WaitWhileBusy()
   
   tell application "FineReader"
      set hasdoc to has document
      if hasdoc then
         close document
      end if
   end tell
   
   WaitWhileBusy()
   
   tell application "FineReader"
      set auto_read to auto read new pages false
   end tell
   
   WaitWhileBusy()
   
   tell application "Finder"
      open theFile using ourApp
   end tell
   
   WaitUntilFinished()
   
   WaitWhileBusy()
   
   tell application "FineReader"
      export to pdf theFile ocr languages enum langEnglish saving type saveSettingsSingleFile image quality imageQualityBalanced export mode pdfLayoutTextUnder with keep page numbers headers and footers and keep pictures
   end tell
   
   WaitUntilFinished()
   
   WaitWhileBusy()
   
   
   tell application "FineReader"
      auto read new pages auto_read
   end tell
   
   WaitWhileBusy()
   
   tell application "FineReader"
      close document
   end tell
   
   WaitWhileBusy()
   
   tell application "FineReader"
      quit
   end tell
   
   delay 5
   
end hazelProcessFile

on WaitWhileBusy()
   repeat while IsMainApplicationBusy()
   end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
   tell application "FineReader"
      set resultBoolean to is busy
   end tell
   return resultBoolean
end IsMainApplicationBusy

on WaitUntilFinished()
   set ourPercent to 0
   repeat while ourPercent < 95
      tell application "FineReader"
         set ourPercent to get document progress
      end tell
      set delayAmt to (100 - ourPercent) / 5
      if delayAmt is greater than 2 then delay delayAmt
   end repeat
end WaitUntilFinished
dragonlady
 
Posts: 3
Joined: Fri Oct 11, 2013 11:59 pm

I have been trying to figure out how to get Hazel to take a series of pdfs placed in a folder (after scanning with a ScanSnap), and OCR each in turn with FineReader Pro.

I appreciate all the work that has been put into this discussion. However, I have not been able to get this to work for me.

Would someone be so kind as to walk me through the setup, step by step? How do I use this script? How do I select the new files in the finder folder so that this script will act on them?

Thanks!
sawbones
 
Posts: 21
Joined: Wed Jul 03, 2013 9:29 pm

Chuggett wrote:Fine Reader does have a bunch of Automator scripts though (found within Automator). I created a folder action in Automator that is run when a document lands in my scanned folder. The finereader script opens the document and OCRs it.

^ @chuggett sorry for being dumb... where did you find these automator scripts? Are you able to post up your script or screenshot?

On doing a search within Automator - There are no OCR functionality or the only one i can see from finereader is convert to PDF?
I'm using FineReader 12. if that makes any difference? Not too sure if FineReader 14 is only for Windows...
jamwithtoast
 
Posts: 9
Joined: Tue Sep 12, 2017 9:22 am

Hello there, I've just purchased Abbyy Finereader pro for Mac v 12.1.14, for use with latest Hazel. (Oddly enough the Fujitsu Finereader software comes with some type of automator i can run "convert to pdf" at the end of hazel and it works but no such thing comes with the paid version of Finereader" Am currently using Fujitsu is1500 with the included Abbyy Finereader OCR software, however because it will only work on pdf's created with Fujitsu scanner must use another Ocr software because I scan at other locations with different scanners and software. They all go into an action folder which Hazel watches. I cannot figure for the life of me how to make AF Pro 12.1.14 ocr the pdf's in ACTION folder so that hazel can read them.
I've researched Automator and Applescript and just found on the Noodlesoft forum what you genuises have created. I'm not a coder of any type and have done some Applescript, but only following specific instructions and cut and paste.

What I'm trying seems pretty simple, especially if I had what came with the the fujitsu Finereader. Simply, is there a clean easy way for me to get this going?, or am I going to have to hire someone to help me with this.

sdbarnes
sdbarnes
 
Posts: 3
Joined: Wed Jul 20, 2016 6:13 pm


Return to Support

cron