Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Please help: Loop hanging --> CTRL Save not executing


  • Please log in to reply
5 replies to this topic
ikeroppi
  • Members
  • 3 posts
  • Last active: Jul 25 2006 02:13 PM
  • Joined: 27 Jun 2006
Hi. I'll try to keep this concise. I could really use some help as I've been banging my head against a wall trying to get this to work.

I'm attempting to automate the OCR (optical character recognition) process in Adobe 7.08 Professional (reference http://www.adobeforu.../webx/.3bbe7163 if you'd like more information).

I'm using Acrobat and AutoHotKey to migrate TIF files from one folder to another location where I save them as PDFs and OCR the text. Everything is working beautifully, except sometimes my AHK loop doesnt appear to execute the line:
Send ^s ;send save keystroke (ctrl+s)
The AHK log file says it has executed, but the save window never opens. If I manually hit CTRL S on my keyboard, the loop continues processing the file and moves on to the next one.

My problem is that this doesn't happen every time I run the script. I have a set of 4 TIF files that I'm processing and the AHK loop hangs on different ones at the "send ^s" line. Occaisionally it runs through all of them without issue. I really want to install this script on a server and not have to monitor it.

I thought the commands might be happening too quickly so I've tried using Sleep functions and WinWait functions, but I've had no luck.

Any help you can provide would be greatly appreciated! :D

The code I'm using (I know its a little lengthy) is below:

#a:: ;;OCR Process 

UnScannedPath=C:\OCR_Analysis\NoOCR\*.tif ;set this variable to your unscanned pdf's 
ScannedPath=C:\OCR_Analysis\OCR\ ;set this variable to the dir of your scanned pdf's 

MsgBox,4, ,Unscanned files expected in %UnscannedPath%`nResults will be in %ScannedPath%`nDid you choose the appropriate language for OCR? 
IfMsgBox, No, Exit 

Loop,%UnScannedPath%, , 1 ;Recurse into subfolders. 
{ 
StringSplit,OutFile,A_LoopFileFullPath,\ ;extract filename 
StringLeft, OutFilePDF, OutFile4, StrLen(OutFile4) - 3
OutFilePDF=%OutFilePDF%pdf

   FileDelete,%ScannedPath%%OutFilePDF% ;delete file, if it exists 

Run %A_LoopFileFullPath% ;start Adobe with the requested file 

winwait,Adobe 

Send, !f ;switch to Files Menu (in German Alt+d=Datei) 
;use !f in the English version of Acrobat (Alt+f=Files) 

Send, {RIGHT}{RIGHT}{RIGHT}{RIGHT} ;point to Document menu 
Send, {DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{ENTER} ;point to Recognize Text Using OCR/Start on the Document Menu
WinWait, Recognize Text

Send {UP}{ENTER} ;all pages 
WinWait, Adobe Acrobat Professional - [%OutFilePDF%],,10

Send ^s ;send save keystroke (ctrl+s)  THIS IS THE PROBLEM LINE
WinWaitActive, Save As
Send %ScannedPath%%OutFilePDF%{ENTER} ;send output filename 

Send ^q ;close Adobe 

WinWaitClose, Adobe Acrobat Professional - [%OutFilePDF%] ;wait until Adobe is closed and start with the next pdf 

} 

msgbox PaperCapture done! 
return

ikeroppi

d-man
  • Members
  • 290 posts
  • Last active: Jun 28 2015 09:26 AM
  • Joined: 08 Jun 2006
maybe try s.th like
slight pause
ctrl down
slight pause
s down
slight pause
s up
slight pause
ctrl up
slight pause

ikeroppi
  • Members
  • 3 posts
  • Last active: Jul 25 2006 02:13 PM
  • Joined: 27 Jun 2006
I tried putting a pause before I run the save command, but I'm unable to un-pause it. I've tried
Pause, On
Pause, Off
But the program just pauses and doesn't un-pause. Advice?

The syntax you provided (slight pause) didn't seem to work for me.
ikeroppi

d- man lo
  • Guests
  • Last active:
  • Joined: --
sorrry, i was just saying what to do , not the exact syntax..

here try this:

sleep 50
send {ctrl DOWN}
sleep 50
send {s DOWN}
sleep 50
send {s UP}
sleep 50
send {ctrl UP}
sleep 50


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Note that {RIGHT}{RIGHT}{RIGHT}{RIGHT} can be abbreviated to {RIGHT 4}...
I will give the reverse advice I gave earlier, elsewhere.
If Send ^s doesn't work, try using WinMenuSelectItem.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

ikeroppi
  • Members
  • 3 posts
  • Last active: Jul 25 2006 02:13 PM
  • Joined: 27 Jun 2006
Well, guys. I've finally had a break-through. Thank you for all of your comments. I tried working with each one of them and then discovered something quite interesting...

I discovered that my problem had something to do with focus on the window. If I clicked over to my Outlook while the script was running, it would execute perfectly. However, if I let it alone, then it would not perform the save functionality. After messing around with several options, I've found one that seems to fix the problem all together - although its still really a mystery to me. For some reason, I HAVE to minimize my PDF while doing the OCR. I then Restore it after it notices the Save As window. Then, I have to activate the Save As window. If I dont minimize and maximize the PDF, then I get no "Save As" window. It seems strange to me, but I thought I would pass it along in case you came across anything like this in your scripts.

I've included the code snippet at the bottom here so you can see the syntax that I ended up with.

Thank you SO much for all of your assistance. It was very much appreciated!

Cheers!

ikeroppi

Send, {RIGHT 4} ;point to Document menu 
Send, {DOWN 5}{RIGHT}{ENTER} ;point to Recognize Text Using OCR/Start in the Document menu
WinWait, Recognize Text
Send {UP}{ENTER} ;all pages 

WinWait, Adobe Acrobat Professional - [%OutFilePDF%],,10
Send ^s ;send save keystroke (ctrl+s) 
WinMinimize, Adobe Acrobat Professional - [%OutFilePDF%]
WinWait, Save As
WinRestore, Adobe Acrobat Professional - [%OutFilePDF%]
WinActivate, Save As
Send %ScannedPath%%OutFilePDF%{ENTER} ;send output filename 

Send ^q ;close Adobe

ikeroppi