Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to detect multiple OK buttons in Script UI dialogue box

  • How to detect multiple OK buttons in Script UI dialogue box

    Posted by Reuben Lara on October 17, 2018 at 12:37 am

    In the code below, I can’t seem to target which button was pressed. Both “Option 1” and “Option 2” should behave like OK buttons (do some code and close the window). What am I doing wrong? Thanks!

    var myWindow = new Window ("dialog");
    myWindow.add ('statictext', undefined, 'Mode:', {multiline: false});

    // some more window input options

    myWindow.add ("button", undefined, "Option 1", {name: "ok"});
    myWindow.add ("button", undefined, "Option 2", {name: "ok"});
    myWindow.add ("button", undefined, "CANCEL", {name: "cancel"});

    if (myWindow.show () == 0) {
    alert("You chose Option 1");
    //execute some code and close the window
    }
    if(myWindow.show () == 1){
    alert("You chose Option 2");
    //execute some code and close the window
    }
    if(myWindow.show () == 2){
    alert("You chose Cancel");
    exit ();
    }

    Reuben Lara replied 7 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 17, 2018 at 6:12 am

    I’m not sure how it’s supposed to work, but it seems like you could set up a unique onClick function for each button, or direct them all to the same function, but have unique names for each button (like “ok1″,”ok2”, and “cancel”) so the function can detect which button was clicked:


    function button_click(){
    if (this.name == "cancel"){
    // do stuff
    }else{
    // do other stuff
    }
    }

    Dan

  • Reuben Lara

    October 17, 2018 at 7:36 pm

    Thanks for the ideas. Tried them and they didn’t respond as expected. In the end, it turns out ScriptUI dialogues can only have one default “OK” button and one default “cancel” button where the window returns either “1” or “0” for OK and Cancel respectively. Script UI detects if the “name” is “ok” or “cancel” to give those buttons default functionality. If multiple buttons have a “name” of “ok”, then only the first one is recognized. So, to add additional buttons that behave like the OK button (i.e. do some code and close the window), see below:

    var myWindow = new Window ("dialog");
    myWindow.add ('statictext', undefined, 'Mode:', {multiline: false});

    // some more window input options

    var additionalOKbutton = myWindow.add ("button", undefined, "Option 1", {name: "option01"});
    myWindow.add ("button", undefined, "Option 2", {name: "ok"});
    myWindow.add ("button", undefined, "CANCEL", {name: "cancel"});

    additionalOKbutton.onClick = function (){
    //execute some code
    //close window
    myWindow.close();
    }

    if (myWindow.show () == 1) {
    alert("You chose Option 2");
    //execute some code
    //window closes automatically
    }else{
    alert("You chose Cancel");
    //execute some code
    exit ();
    //window closes automatically
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy