📜 ⬆️ ⬇️

Handling errors and crashes 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 encountered this type of program departures, for reasons which are 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 start an alarm clock to wake up at night (like a robot) and watch: “Didn't Photoshop fly out” with an error? Then nervously re-run the processing, sorting the already processed files into another folder.
')
In short, here's the problem! (Similarly, you can handle errors from other software). Decision?






How did these errors occur?

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

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

Error windows will be explored 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:



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


Similarly, you can close the error with the text Microsoft Visual C ++ Runtime Library:

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 launching 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" - via the script, respectively ), or if you do not want to use hot keys - using the keyboard up-up, enter, etc ...



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


What have we taught the computer? Close errors that occur, run Photoshop processing. But on closer examination, the computer starts processing in the same folder and does not understand whether the file is processed or not, the “secondary” processing of the files that have been previously processed occurs, and then it goes to the files that need to be processed. What to do?

We will save the processed files to another format, for example png (a raster format for storing graphic information using lossless compression using the Deflate algorithm). By the names of the saved * .png files we will delete our original * .jpeg or * .bmp files. After reviewing the documentation and examples of AutoIt, the following script turned out (looking for * .png files - by their names erases the source * .bmp files) .:

#include <file.au3>
#include <array.au3>

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


Do not forget to add the action File - Save As ... to save the file on saving the png.

It remains to collect all this into a single file, "loop processing" to search for errors. Or add a task to the windows task scheduler (Scheduled Task), which will automatically once every few minutes, check for an error on the computer screen and make decisions for us to close them, close the program, delete the original unprocessed files (according to the list of saved and already processed) files. ), restart Photoshop for processing. The pauses in the script for 10-30 seconds are added for reliability, because sometimes after the occurrence of errors, the computer is not quite correctly and quickly responds to keystrokes.

Source: https://habr.com/ru/post/135290/


All Articles