title: Custom ScriptUI buttons that will close the window
body: <p>For those knowledgeable in ExtendScript &amp; InDesign, I have a ScriptUI question:  How can I have a window close properly after the user picks one button or the other <em>when the buttons are custom choices</em>.  See the code below:</p>
  
  <pre><code>$.writeln("The user pressed " + chooseOyo("123456"));
  
  function chooseOyo(jobNumber) {
      var machine;
      var getOyoWindow = new Window ("dialog", "Which Imagesetter?");
          var textGroup = getOyoWindow.add("group");
              textGroup.orientation = "column";
              textGroup.add("statictext", undefined, "The current job is " + jobNumber);
              textGroup.add("statictext", undefined, "Please choose an imagesetter for this job:");
          var buttonGroup = getOyoWindow.add("group");
              var o1 = buttonGroup.add("button", undefined, "OYO 1");
              var o2 = buttonGroup.add("button", undefined, "OYO 2");
                  o1.onClick = function () {machine = "OYO1";}
                  o2.onClick = function () {machine = "OYO2";}
  
      if (getOyoWindow.show() == 1) {
          return machine;
      } else {
          exit();
      }
  }
  </code></pre>
  
  <p>Fairly simple, no?  Well, so far, the buttons don't do anything and you have to hit [ESC] in order to cancel the window.  How can I get this to work?</p>