Skip to main content
Royi A
Inspiring
April 13, 2009
Question

How To Exit A Script?

  • April 13, 2009
  • 1 reply
  • 41915 views

Hello.

I'm trying to write a script (My First) for Photoshop.

I want to check a condition and if it's true to exit the script.

The problem I can't find any place writing what is the "Exit" command in a script.

Thanks.

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
April 13, 2009

Write your code in a function then you can test for your condition and use return to exit

function main(){

if(someThingIsWrong) return;

}

main();

Royi A
Royi AAuthor
Inspiring
April 17, 2009

I wonder if there's an option that if there's no Document, it will just stop running the script.

Something like:

if (!documents.length) {

     alerts ("There are no Documents");

     Exit (); // A function that stops the script

}

Has anyone succeeded doing it?

How can I write such "Exit" function?

Thanks.

Chuck Uebele
Community Expert
Community Expert
April 16, 2014

Thanks for the advice. and I'll do that

Just out of curiosity is there a way to end a script with a comand, like 'exit()' ?

I know that exit() is not copatible with Extend Script. it just feels as if there has to be some comand like the esc button.


Not that I'm aware of.  Only ways I know is to use the method I mentioned, or, again, put your script in a function and use "return" to exit the function and thus end the script with no further lines to excute.  Or use wrap you code in a catch/try block and throw an error if a condition is not met.