9 Replies Latest reply on Jun 2, 2008 8:14 AM by Bob, Adobe Engineer

    Coming Back to ScriptUI

    Level 1
      Every time I come back to ScriptUI, I feel like I have to learn everything again. This time, I'm trying to keep more careful notes.

      Taking my lead from the JavaScript Tools Guide, I started with this simple script:
      //DESCRIPTION: Hello World using ScriptUI
      
      #target indesign
      displayDialog("Hello World");

      function displayDialog(message) {
        var myDialog = new Window('dialog');
        myDialog.show();
      }
      What the guide doesn't tell you is how to recover from running this script! The only way I know is to force quit InDesign and relaunch. Am I missing something? How do you get InDesign to dismiss this simplest of all ScriptUI dialogs?
        • 1. Re: Coming Back to ScriptUI
          Level 1
          While this does not answer my question, getting the dialog into a state where it is easy to dismiss is quite easy. Just add an "OK" button:
          //DESCRIPTION: Hello World using ScriptUI
          
          #target indesign
          displayDialog("Hello World");

          function displayDialog(message) {
            var myDialog = new Window('dialog');
            var myOKbtn = myDialog.add('button', undefined, 'OK');
            myDialog.show();
          }
          And that text better be 'OK' or you'll have a nasty surprise. Change its name to "Test" and it no longer automatically dismisses the dialog. Aha! But hitting the Esc key dismisses it. Phew, well that's answered my question.

          Dave
          • 2. Re: Coming Back to ScriptUI
            Level 1
            I do the guide an injustice. Using the Esc key to escape is documented at the top of page 70. However, I found that by first stumbling upon how to close a dialog using Escape and then by searching the PDF on the word Escape. It's a full ten pages after the example that creates the problem on page 60.

            I can see why my wife reads documentation from cover-to-cover before doing anything. But it's not my style!

            Dave
            • 3. Re: Coming Back to ScriptUI
              Harbs. Level 6
              Hi Dave.

              Buttons can have a "name" property which can be assigned when created.
              If the name is "ok" it automatically acts as an "Okay" button no matter
              what it's called/ If the name is "cancel" you can guess what it does. ;)

              I have a script UI library which I have been building as I need widgets.
              They might make your life easier. If you're interested, send me an email.

              Harbs
              • 4. Re: Coming Back to ScriptUI
                Level 1
                Harbs,

                Thanks. And thanks for the kind offer. I'm always torn by such possibilities. On the one hand, I like to work things out for myself so I am more confident about what I'm doing. On the other hand, how many wheels should I re-invent?

                Dave
                • 5. Re: Coming Back to ScriptUI
                  Harbs. Level 6
                  Whatever floats your boat... ;)

                  Either way, here's a line of code which creates an Okay button which can
                  be called whatever you want.

                  (okayButtonName is the displayed name variable)

                  group.okayButton = group.add('button', undefined, okayButtonName,
                  {name:'ok'});


                  Harbs
                  • 6. Re: Coming Back to ScriptUI
                    Hi Dave,

                    you need to add the examples to your diet, it's my experience too that the scripting guide(s) just don't cut it. Usually I just browse through a whole stcak of the examples, for scriptUI they are to be found in the Bridge SDK (of course;-).

                    Oh dear Adobites, couldn't you find a way to use Flex as an alternative for ESTK? You can build beautiful interfaces and it's all geared up for great handling of JS-esque code...

                    Pweese? Pwitty pweese?
                    • 7. Re: Coming Back to ScriptUI
                      Level 1
                      I typically ALWAYS put in button onClick handlers.

                      function displayDialog(message) {
                      var myDialog = new Window('dialog');
                      var myOKbtn = myDialog.add('button', undefined, 'OK');
                      myOKBtn.onClick = function() {
                      this.window.close( 1 );
                      }
                      myDialog.show();
                      }

                      The approach Dave used here will not work in some non-english InDesign versions. To have the default OK button feature always work, you have to have the { name: 'ok'} creation property as Harbs said.

                      Bob
                      • 8. Re: Coming Back to ScriptUI
                        Level 1
                        To say that I "used" it is an overstatement. Stumbled upon it is more accurate. I agree that always having an explicit onclick handler is the sensible way to go.

                        Dave
                        • 9. Re: Coming Back to ScriptUI
                          Level 1
                          I somehow lost your email address, Dave.

                          Can you send me an email, I've got something to talk with you about.

                          Bob