Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase FileChangeDir("D:\ocr\import") Global $search $search = FileFindFirstFile("*.pdf") If $search = -1 Then Exit EndIf $totalcount = 0 While 1 $nummovedfiles = MoveTenFiles() If $nummovedfiles == 0 Then ExitLoop OCRFiles() FileDelete("D:\ocr\tmp\*.pdf") $totalcount += $nummovedfiles WEnd FileClose($search) MsgBox(1, "Finished Processing", "Processed " & $totalcount & " files.") Exit Func MoveTenFiles() $count = 0 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileMove($file, "D:\ocr\tmp") $count += 1 If $count >= 10 Then ExitLoop WEnd Return $count EndFunc Func OCRFiles() Local $result Run("C:\Program Files\ABBYY FineReader 9.0\FineReader.exe", "C:\Program Files\ABBYY FineReader 9.0") WinWait("Untitled document - ABBYY FineReader 9.0 Professional Edition") SendKeepActive("Untitled document - ABBYY FineReader 9.0 Professional Edition") Sleep(2000) Send("^w") Sleep(10000) WaitForOCRToFinish() Sleep(2000) WinClose("Untitled document - ABBYY FineReader 9.0 Professional Edition") Sleep(2000) WinWait("ABBYY FineReader 9.0 Professional Edition", "Do you want to save the changes you made") While 1 WinActivate("ABBYY FineReader 9.0 Professional Edition", "Do you want to save the changes you made") SendKeepActive("ABBYY FineReader 9.0 Professional Edition", "Do you want to save the changes you made") Send("n") $result = WinWaitClose("ABBYY FineReader 9.0 Professional Edition", "Do you want to save the changes you made", 2) If $result == 1 Then ExitLoop WEnd Sleep(2000) WinWaitClose("Untitled document - ABBYY FineReader 9.0 Professional Edition") Sleep(5000) EndFunc Func WaitForOCRToFinish() Local $result Local $goodcalls $goodcalls = 0 While 1 $result = WinWaitClose("CONVERT", "", 1) If $result == 1 Then $goodcalls += 1 $result = WinWait("CONVERT", "Process completed", 1) If $result == 1 Then While 1 WinActivate("CONVERT", "Process completed") SendKeepActive("CONVERT", "Process completed") Send("{ENTER}") $result = WinWaitClose("CONVERT", "Process completed", 2) If $result == 1 Then ExitLoop WEnd $goodcalls += 1 EndIf If $goodcalls >= 2 Then ExitLoop Sleep(3000) WEnd EndFunc