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.

Inspiring
April 17, 2009

This is the idiomatic way to do that.

function main() {

   if (app.documents.length == 0) {

      alert("Please open a document before running this script.");

      return;

   }


   // insert code here

};


main();