Stopping an action that calls a script?
-
null
Stopping an action that calls a script?
Assume you have a script that is called as part of an regular Photoshop action. The script pops up a Yes/No dialog box asking the user if they want to continue. Is there any way to abort the remainder of the action if the user click "No"?
-
xbytor
Stopping an action that calls a script?
Code: Select allError.runtimeError(8007);
This throws a 'User Cancelled' exception, which would probably be most appropriate.
Depending on the structure of your code, you may be able to simple do a 'return'. But it's impossible to say without seeing your code. Throwing an exception, however, will almost always work.
-X
This throws a 'User Cancelled' exception, which would probably be most appropriate.
Depending on the structure of your code, you may be able to simple do a 'return'. But it's impossible to say without seeing your code. Throwing an exception, however, will almost always work.
-X
-
null
Stopping an action that calls a script?
Thanks X. Your approach sounds good, but I can't get it to work.
I just have a very simple script to present a yes/no prompt:
if (confirm("Do you want to continue?") == false) {
Error.runtimeError(8007);
}
I then call the above script from a large action. At various points, I call the above script, but want the action to stop when I click "No".
I just have a very simple script to present a yes/no prompt:
if (confirm("Do you want to continue?") == false) {
Error.runtimeError(8007);
}
I then call the above script from a large action. At various points, I call the above script, but want the action to stop when I click "No".
-
xbytor
Stopping an action that calls a script?
If that doesn't work I'm afraid you're out of luck.
-X
-X
-
Timo Autiokari
Stopping an action that calls a script?
The below does work on my CS2, as started from an Action button.
Code: Select allif (confirm("Do you want to continue?") == false) {
Error.runtimeError(8007);
}
alert("passed");
But it is brutal. The user already has pressed the NO button so there really is no need to nag.
With a pure script this is easy to handle, like X briefly explained. Just have the main routine inside a function, then you can nicely return.
Code: Select all//this runs the main routine
main();
function main(){
// code
if (confirm("Do you want to continue?") == false) {
// this jumps to the row below the calling line so a script stops. But action continues.
return;
}
alert("passed");
// more code
return;
}
Timo Autiokari
Code: Select allif (confirm("Do you want to continue?") == false) {
Error.runtimeError(8007);
}
alert("passed");
But it is brutal. The user already has pressed the NO button so there really is no need to nag.
With a pure script this is easy to handle, like X briefly explained. Just have the main routine inside a function, then you can nicely return.
Code: Select all//this runs the main routine
main();
function main(){
// code
if (confirm("Do you want to continue?") == false) {
// this jumps to the row below the calling line so a script stops. But action continues.
return;
}
alert("passed");
// more code
return;
}
Timo Autiokari
-
Timo Autiokari
Stopping an action that calls a script?
Aha. I did test it but I messed up with my action sets. Sorry.
So, you are right, the Action Steps that follow will be executed. The brutal stop will stop only the script but not the remaining Action steps.
Timo Autiokari
So, you are right, the Action Steps that follow will be executed. The brutal stop will stop only the script but not the remaining Action steps.
Timo Autiokari
-
Timo Autiokari
Stopping an action that calls a script?
Forgot to mention, I started experimenting with Scripts by by mixing them into Actions and very rapidly I had a rather desperate mess in my hands. Did not know what belonged to where.
It is far far better approach to write pure scripts, even if they are mostly ScriptListener code. And only start them from Action buttons.
Most of my Scripts are full of SL code, I use the Scripting commands usually as "qlue" and "patch" and for the "finishing touch". SL also runs much faster so I try to use it as much as possible.
Doing the SL is equally easy as recording an Action is. And SL code is relatively easy to generalize.
Timo Autiokari
It is far far better approach to write pure scripts, even if they are mostly ScriptListener code. And only start them from Action buttons.
Most of my Scripts are full of SL code, I use the Scripting commands usually as "qlue" and "patch" and for the "finishing touch". SL also runs much faster so I try to use it as much as possible.
Doing the SL is equally easy as recording an Action is. And SL code is relatively easy to generalize.
Timo Autiokari
-
xbytor
Stopping an action that calls a script?
Timo Autiokari wrote:Most of my Scripts are full of SL code, I use the Scripting commands usually as "qlue" and "patch" and for the "finishing touch". SL also runs much faster so I try to use it as much as possible.
Doing the SL is equally easy as recording an Action is. And SL code is relatively easy to generalize.
I have to recommend using SLCfix script to clean up SL generated code so that it is somewhat readable. It also fixes a couple of minor JS-level bugs that SL occasionally generates.
I also should recommend ActionToJavascript (and related scripts) for converting Actions to Javascript. It's not uncommon for a client to send me an action and say 'I need a script to do what this action does except for X, Y, and X' where X, Y, and Z can only be done via JS. I do the translation and modify the generated JS code.
Both scripts are a part of xtools, naturally.
-X
Doing the SL is equally easy as recording an Action is. And SL code is relatively easy to generalize.
I have to recommend using SLCfix script to clean up SL generated code so that it is somewhat readable. It also fixes a couple of minor JS-level bugs that SL occasionally generates.
I also should recommend ActionToJavascript (and related scripts) for converting Actions to Javascript. It's not uncommon for a client to send me an action and say 'I need a script to do what this action does except for X, Y, and X' where X, Y, and Z can only be done via JS. I do the translation and modify the generated JS code.
Both scripts are a part of xtools, naturally.
-X
-
Andrew
Stopping an action that calls a script?
Using a script you can tell PS to run individual steps of an action, or groups of steps of an action, or all steps from step N. So, you could have a script that says: run the first 5 steps, then issue a dialog, then depending on the response run to the end of the action or abort. Obviously you could also just split the action into two and achieve the same.
Andrew
Andrew
-
IsraelThompson
Stopping an action that calls a script?
For some reason I'm getting an "undefined" error message when using "Error.runtimeError(8007)". I've even got app.displayDialogs = DialogModes.NO set to no avail. Any ideas? Anyone?