Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How terminate script?

New Here ,
Oct 09, 2008 Oct 09, 2008
My script is sometimes long running. I want to add functionality to canceled one:

var fl = true;
var win = new Window('window', '');
var cancelButton = win.add ('button', undefined, 'Cancel');
cancelButton.onClick = function()
{
alert('canceled');
fl = false;
}

win.show();

for (var i = 0; fl && i < 100000; i++)
{

// my code here

app.version;

}

win.close(1);

ScriptUI does not click button.
Here is something not lacking?
TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2008 Oct 09, 2008
Not sure if I understand you, but you can stop execution of your code with: exit();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2008 Oct 09, 2008
sorry

how send this message? button not work
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 09, 2008 Oct 09, 2008
Eh?

cancelButton.onClick = function()
{
alert('canceled');
exit(0);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2008 Oct 09, 2008
Thanks.
However, thus too does not work.

While running script mouse cursor is "beach ball". The button does not work, and alert does not show, etc.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2008 Oct 10, 2008
Either call your for() loop from within the onClick or close the window there
instead, like this.

> cancelButton.onClick = function()
> {
> alert('canceled');
> fl = false;
win.close(1);
> }
>
> win.show();
>
> for (var i = 0; fl && i < 100000; i++) {
>
> // my code here
>
> app.version;
>
> }
>
// win.close(1);


-X
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2008 Oct 10, 2008
hm..

Any way that the _user_ break a prolonged script?

Probably, keyboard shortcut?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2008 Oct 10, 2008
> Any way that the _user_ break a prolonged script?
>
> Probably, keyboard shortcut?

ESC-ESC-ESC-ESC-ESC-ESC-ESC-ESC


The other way is to have a dialog with progress bar and a 'Cancel' button. I
tend to do that with long running Photoshop scripts.

-X
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2008 Oct 10, 2008
>ESC-ESC-ESC-ESC-ESC-ESC-ESC-ESC

ok its good, thanks

>The other way is to have a dialog with progress bar and a 'Cancel' button

In my first message attempt of a write of such dialogue (a progressbar I have removed - with it there are no problems). Difficulty that "beach ball" does not allow the user to press the button.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2008 Oct 10, 2008
ebanat@adobeforums.com wrote:
>
> ESC-ESC-ESC-ESC-ESC-ESC-ESC-ESC
>
> ok its good, thanks

Sometimes you have to repeat yourself with ScriptUI to make yourself heard :)

>
> In my first message attempt of a write of such dialogue (a progressbar I have removed - with it there are no problems).

My implementation is below.


> Difficulty that "beach ball" does not allow the user to press the button.

I've had mixed results. In some scripts it works fine, in others, not at all.
And it varies across Adobe Apps and versions and which OS you happen to be
running on.

Bob Stucky may have a better threaded solution from some of the Bridge UI work
that he's done in the past.


Yet another way of tackling the problem is to have the progress bar UI running
in Bridge. The ID script would launch the progress UI via BridgeTalk and have to
periodically check and update that UI. This has the added advantage that the
progress bar is in a completely separate process from ID so there is no UI
contention going on. I never got around to implementing it, though, as the need
was never really there.



//
// createProgressPalette
// title the window title
// min the minimum value for the progress bar
// max the maximum value for the progress bar
// parent the parent ScriptUI window (opt)
// useCancel flag for having a Cancel button (opt)
//
// onCancel This method will be called when the Cancel button is pressed.
// This method should return 'true' to close the progress window
//
function createProgressPalette(title, min, max,
parent, useCancel) {

var win = new Window('palette', title);
win.bar = win.add('progressbar', undefined, min, max);
win.bar.preferredSize = [300, 20];

win.parentWin = undefined;
win.recenter = false;
win.isDone = false;

if (parent) {
if (parent instanceof Window) {
win.parentWin = parent;
} else if (useCancel == undefined) {
useCancel = !!parent;
}
}

if (useCancel) {
win.onCancel = function() {
this.isDone = true;
return true; // return 'true' to close the window
}

win.cancel = win.add('button', undefined, 'Cancel');

win.cancel.onClick = function() {
var win = this.parent;
try {
win.isDone = true;
if (win.onCancel) {
var rc = win.onCancel();
if (rc != false) {
win.close();
}
} else {
win.close();
}
} catch (e) {
alert(e);
}
}
}

win.onClose = function() {
this.isDone = true;
}

win.updateProgress = function(val) {
var win = this;

if (val != undefined) {
win.bar.value = val;
}

if (win.recenter) {
win.center(win.parentWin);
}

win.show();
win.hide();
win.show();
}

win.recenter = true;
win.center(win.parent);

return win;
};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 11, 2008 Oct 11, 2008
LATEST
BridgeTalk the rules way is similar. However much is unclear
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines