5 Replies Latest reply on May 11, 2016 7:18 AM by DBLjan

    EventListener afterOpen, delay

    DBLjan Level 2

      Hello,

       

      i'm using Dave Saunders script for saving the window-position, which works fine. http://forums.adobe.com/message/1113471#1113471

      A while ago i stumbled upon a script to set metaData to my documents, which works great too. I discovered InD's startup scripts folder. Now I want to merge them together, that the window-pos will be applied after open of every document.

      But not being  firm with javascript at all, i can't solve much issues, which I have now: it seems that the afterOpen handler doesnt wait for the document-window to open. Can anyone help me out choosing the right handler to achieve this, or delay the afterOpen to wait for the window to open?

       

      #targetengine "session"

      main();

       

           function main()

      {

      var myEventListener1 = app.addEventListener("afterOpen", setWindowPos, false);

      }

               

      function setWindowPos()

          {

        // the script from the link obove will go here, but really dont know if i can do this this way because lack of js-skills

          }

        • 1. Re: EventListener afterOpen, delay
          RobertKyle Level 2

          The afterOpen event fires twice, once when the file opens and again when the window opens. You want to delay execution of your setWindowPos function until the window opens. Try this:

           

          function setWindowPos(myEvent) {

              var myTarget = myEvent.target

              if (myTarget.constructor.name == "LayoutWindow") {

                  // stir in your window positioning code

              }

          }

          • 2. Re: EventListener afterOpen, delay
            DBLjan Level 2

            Hi, thank you for your answer,

             

            but this dind't work out.

            I housed it in there, but after open, nothing happens. Theres no error-message either. The script generally works, because it houses also my add metadata thingy.

             

            var myEventListener2 = app.addEventListener("afterOpen", setWindowPos, false);

             

            Do i maybe have to add something where false is, because the function has a (myEvent) behind it? Really dont know much about js.

            Or has it something to do with my german Indesign-Version CS5.5, that "LayoutWindow" has a different name, and how do I read that out what InD need in german?

            • 3. Re: EventListener afterOpen, delay
              RobertKyle Level 2

              Seems likely that "LayoutWindow" is something else in German.

               

              try this:

               

              function setWindowPos(myEvent) {

                   $.writeln(myEvent.target.constructor.name);

              }

               

              when you open a document, the Javascript console should show two entries, one for the file and one for the window.

               

              You can also use alert(myEvent.target.constructor.name). Or create a global variable for myEvent so that you can examine all of its properties in the data browser.

              • 4. Re: EventListener afterOpen, delay
                HenningWinter Level 1

                If you want to avoid the script running twice even when no active window is present, you can add this line:

                targetengine "session"

                main();
                
                function main() {
                     var myEventListener1 = app.addEventListener("afterOpen", setWindowPos, false);
                }
                     
                function setWindowPos() {
                     if(app.layoutWindows.length == 0) return; // Just return when no windows shown avoiding first run...
                     // the script from the link obove will go here, but really dont know if i can do this this way because lack of js-skills
                }
                

                 

                Best regards,

                Henning

                • 5. Re: EventListener afterOpen, delay
                  DBLjan Level 2

                  Whops, this is a bit embarressing, didnt know I had this thread Unanswered.

                  In 2013 i did a workaround, discarding the functionallity of the source-script (to change the size by seting a new master). But since my other coworkers are fine with no palettes at the right side of the screen (where InD draws his docwindow behind), i was the only one using it, so I hard-coded my bounds like this, since my workspace doesnt alter much:

                   

                  #target indesign
                  #targetengine 'dave'
                  
                  (function(){
                            var myEventListener = app.eventListeners.add("afterOpen", testFunction, false);
                  
                          function testFunction() {
                                      app.layoutWindows[0].bounds = [71, 35, 1064, 1618];
                            }
                  }())
                  
                  1 person found this helpful