Skip to main content
Known Participant
June 6, 2021
Answered

I want to hit cancel button in scripts

  • June 6, 2021
  • 1 reply
  • 4038 views

I want to hit cancel button in entire scripts, when user is click cancel button , It will be exist enitre scripts,

Thanks in Advance

 

Here is code, But is not working, Please modify the scripts

var run = true

var dlg = new Window('dialog')

dlg.cancelBtn = dlg.add('button',undefined,'Cancel')

dlg.cancelBtn.onClick = function(){run = false}

 

if(run){

    //your code

    }

 

 

 

This topic has been closed for replies.
Correct answer r-bin

if i change palette it works automatic and cancel button does not work...

I w

var run = true

var dlg = new Window('palette')

dlg.cancelBtn = dlg.add('button',undefined,'Cancel')

dlg.cancelBtn.onClick = function(){run = false; dlg.close();}

dlg.cancelElement = dlg.cancelBtn; // do it if name != 'Cancel'

dlg.show();

if(run){

//Code is Run Automatic When Script is run 
alert("your code");
}


It works. Only the script takes away all the resources of Photoshop, and there is no time left to process the click. Put Actions in StepByStep mode or use refresh() from time to time.

var time0 = $.hiresTimer;
var time = time0;

var run = true

var dlg = new Window('palette')

dlg.cancelBtn = dlg.add('button',undefined,'Cancel')

dlg.cancelBtn.onClick = function(){run = false}

dlg.show();

while(run){

    
    app.beep(1000);
    $.sleep(200);

    time += $.hiresTimer;
    if (time > 2000000) { time = $.hiresTimer; refresh(); }
    }

 

Or use doProgress.

 

doForcedProgress("the script", "f()");

function f()
    {
    while (1)
        {
        if (!app.updateProgress(0,0)) return;

        
        app.beep(1000);
        $.sleep(200);
        }
    }

 

1 reply

Legend
June 6, 2021

var run = true

var dlg = new Window('dialog')

dlg.cancelBtn = dlg.add('button',undefined,'Cancel')

dlg.cancelBtn.onClick = function(){run = false; dlg.close();}

dlg.cancelElement = dlg.cancelBtn; // do it if name != 'Cancel'

dlg.show();

if(run){

//your code
alert("your code");
}

MXKSAuthor
Known Participant
June 6, 2021

I want to run code part automatically, It's showing only window not run to code blocks

 

var run = true

var dlg = new Window('dialog')

dlg.cancelBtn = dlg.add('button',undefined,'Cancel')

dlg.cancelBtn.onClick = function(){run = false; dlg.close();}

dlg.cancelElement = dlg.cancelBtn; // do it if name != 'Cancel'

dlg.show();

if(run){

//Code is Run Automatic When Script is run 
alert("your code");
}

Legend
June 6, 2021