5 Replies Latest reply on Jan 11, 2012 9:21 PM by jonht

    Get all InDesign globals

    absqua Level 4

      I'd like to get a list of all of InDesign's globals. (I've lately been using the Sublime Text 2 editor with the SublimeLinter plugin and JSHint, and want it to stop bothering me about undefined variables.)

       

      I retrieved all the class names from the OMV prefs file (thanks Jongware!) and now just want to get the other globals (app, exit, File, etc.). There aren't that many, but I don't understand why this:

       

      for (var i in this) {
           $.writeln(i);
      }
      

       

      will print only a weird grab-bag of property names. Some of the properties that don't come back are non-enumerable (including exit and File), so I guess that makes sense, but

       

      this.propertyIsEnumerable("app");
      

       

      for instance, returns true, but isn't printed by the for...in loop.

       

      So, two questions:

       

      1. Why don't app and other enumerable properties of the global object print in the above example? and

      2. Is there any way to retrieve the non-enumerable property and method names?

       

      Jeff

        • 1. Re: Get all InDesign globals
          Marc Autret Level 4

          Hi Jeff,

           

          1) Provided that this===$.global, the property app should be enumerated in your for...in loop. It's strange that you don't see that key. On my platform, 'app' in $.global is true. You should check this:

           

          alert( $.global.reflect.properties );

           

          2) The non-enumerable properties of the global object usually are its methods (simple functions such as exit, or object constructors such as File). By definition the for...in loop won't retrieve those keys, but you can grab them with:

           

          alert( $.global.reflect.methods );

           

          @+

          Marc

          • 2. Re: Get all InDesign globals
            absqua Level 4

            Perfect. Thanks Marc. I've not had occasion to use reflect before.

             

            (While I do get true for 'app' in $.global, the for...in loop won't print it—unless I've accessed app earlier in the script.)

            • 3. Re: Get all InDesign globals
              jonht Level 1

              HI Jeff,

              WIth sublime, can it trigger indesign to run the script like the ESTK can?

               

              Does anyone else use an alternative that can control indesign?

              Cheers

              John

              • 4. Re: Get all InDesign globals
                absqua Level 4

                Hi John. I'm really just getting into using Sublime. Right now I use its build system to use osascript to run a tiny Applescript that tells InDesign (using do script) to run the current JavaScript file. It works, but of course you can't set breakpoints or step through anything...

                 

                Jeff

                • 5. Re: Get all InDesign globals
                  jonht Level 1

                  Ok thanks for the info.