Copy link to clipboard
Copied
I have a Script UI dialog box that is displayed within my script asking for user input on what to do next (two buttons).
However, because it is part of a batch script I'd like the script to automatically click a default buton after a predetermined amount of time so that the script doesn't hang up waiting for user input.
I'm good with creating the timer, but I haven't figured out how to make it run while the dialog is still displayed. It seems like I can get it to start timing either BEFORE the dialog is displayed or AFTER the dialog is closed, but not WHILE it is displayed.
Edit: is there an onLoad that I could add to the window element?
Copy link to clipboard
Copied
I think that's going to be a hard one to do, as the UI locks things up until it's dismissed. Just out of curiosity, is this something others are going to use or just for your own use? You can always program the script to bypass the UI if conditions are met, like a particular user ID. Even if you got the timer to run, you might have problems dismissing the UI. I had this issue with AS3. It seems there is a security feature that doesn't allow you to program something that is suppose to be user interaction.
Copy link to clipboard
Copied
Thanks for your response, Chuck.
It's for others to use. And yes, that is exactly what happens--the UI hangs up all processes until one of the buttons is clicked.
Copy link to clipboard
Copied
I've only done a little with extensions, but that might be a way around this. You can have a modeless panel, which will allow you to use the timer function. I just don't think you can do that with the standard UI. I used Brackets for the few panels I made, and it sets up pretty easy. Just a bit of HTML coding and CSS, but all your JS is integrated for you.
Copy link to clipboard
Copied
Your "modeless panel" comment may have just helped me out.
I didn't consider the dialog vs. palette window types, but I've worked with both in the standard UI so that's something I'll look into.
Copy link to clipboard
Copied
Use a palette window type. The code would basically do the following.
This may or may not work. It's supposed to but palette window behavior over the years has not always been consistent.
Copy link to clipboard
Copied
We're on the same page. I'll see if I can get it to work.
Thank you both for your suggestions.
Copy link to clipboard
Copied
I know DBarranca Davide Barrenca was trying to get modeless UIs to work without much success, so he's been doing a lot with extensions.
Copy link to clipboard
Copied
Hi,
I've blogposted in the past about ScriptUI palettes, you can have a look here:
http://www.davidebarranca.com/2012/10/scriptui-window-in-photoshop-palette-vs-dialog/
and
ScriptUI – BridgeTalk persistent Window examples | Photoshop, etc.‌
True, support for palette (which officially are not supported) depends on the version and the platform and it's a headache.
Good luck 🙂
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com
Copy link to clipboard
Copied
I created this scaled-down version of the palette to see if I could get it to work. The palette is showing for the desired amount of time, but there are two issues. I'm hoping that there's some simple solutions that I'm not seeing.
1) The buttons aren't changing the value of a dummy variable as I expected them to (this could be due to the way I have set up the timer in a while loop), the sleep function had similar results
2) I was hoping to catch instances when the user clicks one of the buttons that it would escape the timer rather than waiting for the timer to complete
Any thoughts would be appreciated.
#target photoshop
app.bringToFront();
app.displayDialogs = DialogModes.NO;
// dummy variable
foo = true;
optionWin = new Window('palette');
optionWin.grpButtons = optionWin.add('group');
optionWin.grpButtons.btn1 = optionWin.grpButtons.add('button', undefined, 'btn1');
optionWin.grpButtons.btn1.onClick = function() {
// change dummy variable
foo = false;
};
optionWin.grpButtons.btn2 = optionWin.grpButtons.add('button', undefined, 'btn2');
optionWin.grpButtons.btn2.onClick = function() {
// change dummy variable
foo = false;
};
optionWin.center();
optionWin.show();
// keep palette busy (i.e., showing) for 5000ms
var startTime = new Date().getTime();
while ( new Date().getTime() - startTime < 5000 ) {}
// see if buttons worked
alert(foo);
Copy link to clipboard
Copied
Try adding following in the while loop, that probably locks up everything, i.e. your onClick never gets called.
optionWin.update()
app.refresh()
For #2 change the while condition to be "(foo == true) && (new Date().getTime() - startTime < 5000)" so it breaks when variable changes
Copy link to clipboard
Copied
Thanks! I only needed to add "optionWin.update()" inside the while loop to get the onClick to be recognized.
The following is a WORKING timed palette with early exit upon button click.
#target photoshop
app.bringToFront();
app.displayDialogs = DialogModes.NO;
// dummy variable
foo = true;
optionWin = new Window('palette');
optionWin.grpButtons = optionWin.add('group');
optionWin.grpButtons.btn1 = optionWin.grpButtons.add('button', undefined, 'btn1');
optionWin.grpButtons.btn1.onClick = function() {
// change dummy variable
foo = false;
};
optionWin.grpButtons.btn2 = optionWin.grpButtons.add('button', undefined, 'btn2');
optionWin.grpButtons.btn2.onClick = function() {
// change dummy variable
foo = false;
};
optionWin.center();
optionWin.show();
// keep palette busy (i.e., showing) for 5000ms
var startTime = new Date().getTime();
while ( new Date().getTime() - startTime < 5000 && foo ) {
optionWin.update();
}
// see if buttons worked
alert(foo);
Copy link to clipboard
Copied
Don't remember exactly why I ended up with that, but I think there was some different behaviour between Win & Mac. So if you experience issues try the other.