Regain focus on ScriptUI window

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

kjell
Posts: 8
Joined: Wed Nov 30, 2016 1:11 pm

Regain focus on ScriptUI window

Post by kjell »

Trying to circumvent the non-modality of ScriptUI's windows, I tried closing the window and recursing back.
But on the second (and following) invocations, the window does not have focus. Is there a way to focus on the window
so the user doesn't have to click on it first?

Code: Select all


var i = 0;

function main() {
var w = new Window ("dialog");
w.text = "iteration " + i++;
var b = w.add ("button", undefined, "Button");
b.onClick = function() {
w.close();
main();
w.show();
}
w.add("button", undefined, "Cancel");
w.show();
}


main();
kjell
Posts: 8
Joined: Wed Nov 30, 2016 1:11 pm

Re: Regain focus on ScriptUI window

Post by kjell »

Found the solution myself:

Code: Select all


var i = 0;

function main() {
var w = new Window ("dialog");
w.text = "iteration " + i++;
var b = w.add ("button", undefined, "Button");
b.onClick = function() {
w.close();
w = main();
w.active = true;
w.show();
}
w.add("button", undefined, "Cancel");
return w;
}


var w = main();
w.show();