8 Replies Latest reply on Nov 14, 2012 2:40 PM by PeterLewisHC

    [ScriptUI] [Mac] Unpredictable Window 'show' event (?)

    Marc Autret Level 4

      Hi fellows,


      I'm lost in a critical bug which I find no plausible explanation.


      Basically, I have a ScriptUI-based dialog (modal) whose creation is done by a function:


          var win = createMyDialog(settings);


      then, as usual, I use win.show() to launch the UI.


      Among other things, createMyDialog() attach to the window an event listener that manages the 'show' event. Also, it makes a certain widget active through myWidget.active = true. So, very simplified, the building function works as follows:


      function createMyDialog(/*...*/)
          var w = new Window('dialog',"Title"),
              /* a number of widgets are added */
              myWidget = w.add('edittext');
          // At some point...
          // ---
          myWidget.active = true;
          // At some point...
          // ---
          w.addEventListener('show', function(){/*do things*/});
          return w;


      According to the beta-testers:


      • The UI perfectly works on all Windows platforms (InDesign CS4 to CS6).


      • It also generally works on all OS X platforms (InDesign CS4 to CS6).


      • A few users reported a "Bad argument" error (JS) whose I can't find the exact location (as my script is delivered in the binary compiled format). One user reports the bug in OS X 10.6.8 and all ID versions from CS4 to CS6; another user reports the bug in OS X 10.5.8 and ID CS5.5. However, other users having the same environments didn't report any bug!


      From this I conclude that the bug is Mac-specific, not specific to the ID's version, and apparently not specific to the Mac OS version.


      Anyway, I'm using a 'log' system that allows me to trace and report some events before the bug occurs. And this has revealed a very weird fact: users who encounter the bug have the 'show' event listener triggered BEFORE the execution of the w.show() statement!!! In other words, the handler which is supposed to be executed only when the dialog is going to be shown through w.show(), is in fact executed during the construction—which of course leads to crazy things. Note that the Window.show() method is never invoked in createMyDialog().


      It seems unbelievable to me, but I have good reasons to suspect that this bug is related to the way I play with myWidget's active property. I try to elucidate how this can happen, whether the Apple Events layer is involved, or whether any system-related parameter could explain such behavior.


      Thanks by advance for any clue or suggestion to solve this.