Copy link to clipboard
Copied
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
}
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
...
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I am generally not a friend of emojis but: Well put!
Copy link to clipboard
Copied
You may want to explain in more detail what you are trying to achieve or actually post the code itself.
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
When scripts is run , code is automatically run and cancel button also work
I hope you have understand.
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
What is purpose of 1000 in beep()?
Copy link to clipboard
Copied
Put 1001.
It's just code. To understand that it is being executed, a signal is emitted.
upd
I thought it was the frequency. This is from another opera. :)))
Copy link to clipboard
Copied
In this script It's looping again and again, Just run the script if user will cancel entire script cancel,
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
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(); }
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
}
Copy link to clipboard
Copied
After I add after Md, Fl, Fl, Nw and Mk extra space it works for me as should.
Copy link to clipboard
Copied
Send me script file how to works
Copy link to clipboard
Copied
Edit your script. After those unfull characters (as they should be 4 long), add another space.
Copy link to clipboard
Copied
Send me, what shoud use
Copy link to clipboard
Copied
Do it yourself, or tell me what you don't understand from that I said.
Copy link to clipboard
Copied
Cancel button can't hit, i want cancel when is script is run , In this scripts Running automatically code but cancel button not works
Copy link to clipboard
Copied
I say it works for me, the code with little corrections I made. Wait for r-bin for more help 😉
Copy link to clipboard
Copied
Who do you want the script for?
If for yourself, then let's give the script code, say the version of photoshop and OS.
Maybe we can think of something.
In any case, having a button (even in the case of doProgress) slows down execution.
If the script is for some uncle, then sorry...
Copy link to clipboard
Copied
Window 10 OS, and Photoshop CC 2021
In this script, loop again and again, I want only when script is run if i wish cancel , the entire scripts is cancel
that's it.
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
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();
if(run){
// app.beep(1000);
$.sleep(200);
time += $.hiresTimer;
while (time > 1) { time = $.hiresTimer; refresh(); }
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
}
Copy link to clipboard
Copied
Your script is not infinite (or long in time). It instantly performs one action (like creating a document) and ends.
The user does not need to press the button, he still will not have time.
Let's take your specific example with long running code. And don't put the code for the "Cancel" button in there.
Advice. To stop the script simply press and hold the Escape button.
Copy link to clipboard
Copied
I Created Long time in scripts, But i want apart from another code. its just a example.
If script is long time and user wish to click on cancel button , To entire script is cancel and exit.
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
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();
if(run){
// app.beep(1000);
$.sleep(200);
time += $.hiresTimer;
while (time > 1) { time = $.hiresTimer; refresh(); }
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO); var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(sTID("artboard"), false);
desc2.putClass(cTID('Md '), sTID("RGBColorMode"));
desc2.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 2592);
desc2.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 864);
desc2.putUnitDouble(cTID('Rslt'), cTID('#Rsl'), 300);
desc2.putDouble(sTID("pixelScaleFactor"), 1);
desc2.putEnumerated(cTID('Fl '), cTID('Fl '), cTID('Wht '));
desc2.putInteger(cTID('Dpth'), 8);
desc2.putString(sTID("profile"), "sRGB IEC61966-2.1");
var list1 = new ActionList();
desc2.putList(cTID('Gdes'), list1);
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
desc1.putInteger(cTID('DocI'), 206);
executeAction(cTID('Mk '), desc1, DialogModes.NO);
}
Copy link to clipboard
Copied
This is meaningless code. Moreover, with errors.
In short. Stopping a script using an interface button is a tricky task. It is solved for each script individually.
The task is not for beginners who cannot write a three-line script that works and they understand how it works.