Skip to main content
Brainiac
November 17, 2019
Answered

Scripting: can I throw an error in the standard batch from script?

  • November 17, 2019
  • 4 replies
  • 2687 views

I have a script that is often used in conjunction with standard batch processing. The behavior of the script depends on the user's settings and there are situations when it ends with an error. However, batch processing does not end at the same time - it opens the next file and the script terminates again and again with an error and so on until the files run out.

 

Is there a way to tell the standard batch processor that the script completed with an error so that it stops processing (i.e., something like when batch processing cannot complete the operation and suggests stopping)?

This topic has been closed for replies.
Correct answer r-bin
Radical way )
 
If an error occurs, if there are no unsaved open documents, the script will create an empty new doc and make any step in the history.

Next, run the command.

 

executeAction(stringIDToTypeID("quit"), undefined, DialogModes.NO);

 

P.S. The "stop" command fails as well as an error throw. Probably a bug in all versions of Photoshop ))

 

 

4 replies

martinj65399781
Known Participant
October 25, 2020

Hey, this is a old one but this one help me top stop batch processing.

This script avoid the error message and doesn't quit photoshop. But it can be better i just don't know how to do it yet.

You just have to create a new document and make a random modification so it will ask you if you want to save it, then you can stop the batch processing without quitting photoshop. not very academic but it works.

 

//avoid the error message if no document is open

if (documents.length == 0){

if (confirm("is a batch processing running ?") == true){
alert("The batch processing will crash ")
app.documents.add(800 ,400 ,72 , "new document", NewDocumentMode.RGB)
var textlayer = app.activeDocument.artLayers.add()
textlayer.name = "my texte"
textlayer.kind = LayerKind.TEXT
var contenutext = app.activeDocument.artLayers["mon texte"].textItem
contenutext.contents = "you can close this document without saving it"
alert("Click on "stop" the processing and then on "cancel" if you don't want to quit photoshop ")

executeAction(stringIDToTypeID("quit"), undefined, DialogModes.NO)

}
}

else{

//you're script here

}

 

 

note that the text layer is only here to guide the user, you can just create an empty layer it will work just fine.

i bet there is another "executeAction>quit" that can break the loop of the batch processing, but i don't know wich one.

 

Hope the will help.

martinj65399781
Known Participant
October 25, 2020

your* sorry for the bad english oupsii

jazz-yAuthor
Brainiac
October 26, 2020

Thanks. However, the problem is that the script does not always work in conjunction with batch and generating a new document window on every error is not the best solution, since it will interfere with work.
I did it differently - I just wrote my batch processor 🙂

Brainiac
November 19, 2019

First of all, you don't need to use Batch. Just do a loop in your script.

You could also set a variable (flag) when you trap the error and then test for that flag for each file, and just close the files instead of continuing to process.

jazz-yAuthor
Brainiac
November 19, 2019

This is obvious, but it does not correspond to the tasks that I solved when writing a script 🙂

r-binCorrect answer
Brainiac
November 18, 2019
Radical way )
 
If an error occurs, if there are no unsaved open documents, the script will create an empty new doc and make any step in the history.

Next, run the command.

 

executeAction(stringIDToTypeID("quit"), undefined, DialogModes.NO);

 

P.S. The "stop" command fails as well as an error throw. Probably a bug in all versions of Photoshop ))

 

 
JJMack
Adobe Expert
November 17, 2019

If you use an script in an action and the script has dependencies on settings or document content  make the settings  or document content before the actions script step. The script will fails if a dependency is missing. If you get an error messages you need to cancel the processing there has been an error. If the Batch stop on error] does not stop  batch process.

JJMack
jazz-yAuthor
Brainiac
November 17, 2019

That’s the problem: if the script is written by user as a command in the actions panel, batch cannot understand whether there was an error while executing the command or not (even if I took into account and processed this error inside the script)
As an example, in video i call to the "example" command in the operation panel contains a call to the script "Source1.jsx", which contains obviously inoperative code that causes an error. Batch does not notice that the script was executed with an error and continues execution for each file ( stop for errors is enabled). Of course, I can handle this error inside the script, but this will not change the situation - the script will not be able to stop the batch until all files are opened.

 

 

Is there any way to stop the batch in such a situation? (i.e. shut down the script so that the batch understands that an error has occurred)