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

How To Exit A Script?

  • April 13, 2009
  • 1 reply
  • 41858 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.

Known Participant
April 16, 2014

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.


The methods you mentioned are some of the ones I've tried but I couldn't get the

"return" or "wrap code in a catch/try block and throw an error if a condition is not met" to work with the code I've posted.