2 Replies Latest reply on Jun 30, 2010 10:51 AM by brettpolo

    [CS5]Run a script on document open

    brettpolo

      Is it possible to automaticly run a script every time a document is opened?

       

      Application has the event listener "beforeOpen", which won't work, because the document isn't yet open, and Document has the event listener "afterOpen", but that can't be added until after the document is already open, so i'm not quite sure what use it is.

       

      Any help would be much appreciated.

       

      /dan

        • 1. Re: [CS5]Run a script on document open
          Kasyan Servetsky Level 5

          ...and Document has the event listener "afterOpen", but that can't be added until after the document is already open, so i'm not quite sure what use it is.

          You can do this --  here is an example:

           

          #targetengine "MyEngine"
           
          var myEventListener = app.eventListeners.add("afterOpen", myDocOpen, false);
           
          function myDocOpen(myEvent)
          {
               var myDoc = app.documents[0];
              myDoc.pages.add(LocationOptions.AT_END);
          }
          

           

          It is important to use app.documents[0] instead of app.activeDocument when you are using afterOpen event.

          This simple script adds a new page every time a document is opened. Written and tested on CS3, windows.

           

          Kasyan

           

          P.S. I just tested it on CS5 -- it works here as well, however it adds two pages instead of one for some reason.

          • 2. Re: [CS5]Run a script on document open
            brettpolo Level 1

            Thanks, Kasyan,

             

            that works exactly how I want it to.

             

            /dan