We process errors and crashes of proprietary programs

    If you were engaged in batch processing in Adobe Photoshop using the Automate-Batch tool (batch processing of a very large number of graphic files with filters applied from the program in automatic mode), you probably came across this type of program crashes, for reasons not clear to me:





    Of course You can wait for the appearance of these errors, which can occur after an hour of processing or after a few hours, you can set an alarm to wake up at night (like a robot) and watch: “Did Photoshop fly out” with an error? Then nervously start processing again, sorting already processed files into another folder.

    In short, this is the problem! (Similarly, you can handle errors from other software). Decision?






    How did these errors come about?

    I decided to process the video using Photoshop filters. Imported Mov into VirtualDub using plugins. Made a storyboard File - Export - Image Sequence, ordered a file name, file type, number of digits, folder. Exported mov to a huge number of bmp files and started batch processing in Photoshop. The result of the processing was then planned through VirtualDub to be exported to the finished avi file, using the Deshaker filter, which will eliminate camera shake. But then Photoshop crashes began, for example, when simply saving to the png file as an error, “Because the file-format module cannot parse the file” (photoshop generates an error saying that it cannot parse in the file-format module?),

    We will handle Photoshop errors using AutoIt scripting language. To do this, we need to be patient with coffee : expect errors to occur, describe how to respond to them, test, assemble a ready-made solution in the form of an exe file with ready-made and automated computer actions.

    We will examine error windows using an AutoIt tool called AutoIt Windows Info. Surprisingly, Adobe Photoshop windows do not use standard windows Api windows, but the program sees error messages without problems: Similarly, you can close the error with the Microsoft Visual C ++ Runtime Library text:



    if WinExists("Adobe Photoshop CS3 Extended","OK") then
    WinWait("Adobe Photoshop CS3 Extended","OK")
    ;ждем окно 30 секунд с ошибкой и кнопкой OK и делаем его активным
    sleep(3000)
    WinActivate("Adobe Photoshop CS3 Extended","OK")
    sleep(3000)
    ;ControlClick("Adobe Photoshop CS3 Extended","OK","[CLASS:Static; INSTANCE:2]")
    ;WinClose("Adobe Photoshop CS3 Extended","OK")
    sleep(3000)
    ;msgbox(1,"1","1")
    ;окно для теста, что все нормально
    ;если не помогло нажатие на кнопку, просто закроем Adobe Photoshop
    ProcessClose("Photoshop.exe")
    endif




    if WinExists("Microsoft Visual C++ Runtime Library","") Then
    winwait("Microsoft Visual C++ Runtime Library","")
    WinActivate("Microsoft Visual C++ Runtime Library","")
    winclose("Microsoft Visual C++ Runtime Library","")
    ;msgbox(0,"First","1")
    EndIf

    sleep(10000)

    if WinExists("Photoshop.exe - Application Error","OK") Then
    winwait("Photoshop.exe - Application Error","OK")
    WinActivate("Photoshop.exe - Application Error","OK")
    controlclick("Photoshop.exe - Application Error","OK","[CLASS:Button; INSTANCE:1]")
    EndIf

    sleep(10000)

    if WinExists("Photoshop.exe - Application Error","OK") Then
    WinActivate("Photoshop.exe - Application Error","OK")
    winwait("Photoshop.exe - Application Error","OK")
    controlclick("Photoshop.exe - Application Error","OK","[CLASS:Button; INSTANCE:1]")
    EndIf

    sleep(10000)


    Errors are processed, the program closes. You must start it again. Hot keys for starting batch processing AdobePhotoshop in the English version Alt + f (File) - u (aUtomate) - Alt + a (Action) - to select our profile for processing - we will use the down arrow keys (“on the keyboard” - through the script, respectively ), or if you do not want to use hot keys - using the keyboard up and up, enter, etc ... What have we already learned about the computer? Close errors that occur, start Photoshop processing. But upon careful consideration, the computer starts processing in the same folder, and does not understand whether the file has been processed or not, there is a “secondary” processing of previously processed files, and then it goes to the files that need to be processed. What to do?



    ShellExecute("C:\Program Files\Adobe\Adobe Photoshop CS3\Photoshop.exe","","C:\Program Files\Adobe\Adobe Photoshop CS3\")
    sleep(30000)
    ;ждем подольше, иначе компьютер вслепую начнет отправлять нажатия клавиши в воздух!
    IF WinExists("Adobe Photoshop CS3 Extended","") Then
    WinActivate("Adobe Photoshop CS3 Extended","")
    Send("!f")
    ;File
    sleep(5000)
    Send("u")
    ;aUtomate
    sleep(5000)
    Send("b")
    ;Batch
    sleep(5000)
    ;старый вариант - через меню подъем курсора снизу вверх
    ;send("{UP}")
    ;sleep(10000)
    ;send("{UP}")
    ;sleep(10000)
    ;send("{UP}")
    ;sleep(10000)
    ;send("{UP}")
    ;sleep(1000)
    ;send("{UP}")
    ;sleep(10000)
    ;send("{UP}")
    ;sleep(10000)
    ;send("{UP}")
    ;sleep(10000)
    ;send("{ENTER}")
    ;sleep(10000)
    ;send("{ENTER}")
    ;sleep(10000)
    ;Set - выбираем - тип настроек профиля для обработки. В моем случае он третий по счету, поэтому нужно _нажать_ 2 раза клавишу на клавиатуре со стрелкой вниз
    send("!t")
    sleep(10000)
    send("{DOWN}")
    sleep(10000)
    send("{DOWN}")
    sleep(10000)
    send("{ENTER}")
    EndIf




    We will save the processed files in a different format, for example png (a raster format for storing graphic information that uses lossless compression using the Deflate algorithm). By the names of the saved * .png files, we will delete our original * .jpeg or * .bmp files. After examining the documentation and AutoIt examples, we got the following script (it searches for * .png files - by its names it erases the * .bmp source files): Do not forget to add the action File - Save As ... to save the file to save png. It remains to collect all this into a single file, "loop processing" to find errors. Or add a task to the windows task scheduler (Scheduled Task), which will be automatically every few minutes, check

    #include
    #include

    Dim $szDrive, $szDir, $szFName, $szExt

    sleep(10000)

    $flagvixod = 0

    ; Shows the filenames of all files in the current directory.
    $search = FileFindFirstFile("*.png")

    ; Check if the search was successful
    If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    ;считаем что все обработано - т.к. нет уже готовых файлов png
    Exit
    EndIf

    While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $TestPath = _PathSplit(@ScriptDir & "\" & $file, $szDrive, $szDir, $szFName, $szExt)
    ;3 = name , 4 = extension
    ;получим имя файла png и заменим его на bmp и сотрем!
    DelMyFile($TestPath[3] & ".bmp")

    WEnd

    Func DelMyFile($value)
    ;msgbox (0,"0",$value)
    ;return $value
    If FileExists($value) Then
    filedelete($value)
    Else
    Return $value
    endif
    EndFunc




    look for an error on the computer screen and make a decision for us - close them, close the program, delete the original unprocessed files (from the list of saved and already processed), restart Photoshop for processing. Pauses in the script for 10-30 seconds are added for reliability, as sometimes after errors occur, the computer does not quite correctly and quickly respond to keystrokes.

    Also popular now: