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

Simulate button press in script UI

Community Beginner ,
Jul 29, 2015 Jul 29, 2015

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?

TOPICS
Actions and scripting

Views

4.0K

Translate

Translate

Report

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
Adobe
Community Expert ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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 Beginner ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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 ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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 Beginner ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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
Advisor ,
Jul 30, 2015 Jul 30, 2015

Copy link to clipboard

Copied

Use a palette window type. The code would basically do the following.

  • Create a palette window.
  • Register onClicks for your buttons that save which button was pressed.
  • Show the window.
  • $.sleep() for however long you want the window to be visible.
  • After the sleep is finished, check to see which if any of the buttons were pressed.
  • Close the window.
  • Continue your script.

This may or may not work. It's supposed to but palette window behavior over the years has not always been consistent.

Votes

Translate

Translate

Report

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 Beginner ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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 ,
Jul 30, 2015 Jul 30, 2015

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.

Votes

Translate

Translate

Report

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
Advocate ,
Jul 30, 2015 Jul 30, 2015

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

Votes

Translate

Translate

Report

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 Beginner ,
Jul 30, 2015 Jul 30, 2015

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);

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 01, 2015 Aug 01, 2015

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

Votes

Translate

Translate

Report

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 Beginner ,
Aug 01, 2015 Aug 01, 2015

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);

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 01, 2015 Aug 01, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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