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.

Known Participant
April 16, 2014

I would strongly recommend putting everything you want to run in a function that you can then check for conitions at the beginning of the script.  Then you can either run the function or not run it.  Also, with every closing "}", make a comment on what it's for.  like:

};//end function runProg

This way you can easily keep track of those.  You should be able to just dump your entire script into a function after your if statement without breaking anything.  700 lines is not that much for scripting.  The main script I use at work has 6,738 lines.  It's broken down into functions for various parts so that if something is not met, the script can end.


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.