Skip to main content
Royi A
Inspiring
April 13, 2009
質問

How To Exit A Script?

  • April 13, 2009
  • 返信数 1.
  • 41915 ビュー

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.

このトピックへの返信は締め切られました。

返信数 1

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 A作成者
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

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.


Here's an example for the catch/try block:

try{//all you code in here

     var run = true

     var errorName = 'stop'

     alert('one');

     if(!run){throw errorName} //the "!" stands for "not"

     //so if your conditions are not met, the if statement throws the error

     //and stops the script    

     alert('two');

}//end try

catch(e){}