2 Replies Latest reply on Jun 10, 2016 6:59 AM by Johnwhite

    double event for start up script

    Johnwhite Level 1

      Hi experts,

       

      is that possible to set multi event for start up script?

       

      like this:

       

          var mySaveCopyEventListener = app.eventListeners.add("afterOpen", doBackup) = app.eventListeners.add("beforeSave", doBackup);   
      

       

      aim to let indesign backup after open, and before save.

       

      thanks

      regard

      John

        • 1. Re: double event for start up script
          Marc Autret Level 4

          Hi John,

           

          The short answer is definitely YES, in the sense that you can use the same event handler as the callback function of various event listeners. Just make sure you understand the distinction between

          (1) the event(s) you want to listen to

          (2) the event handler (doBackup, in your case)

          (3) the event listener(s) which just map (1) to (2).

           

          The issue in your code above is that you don't seem to make the distinction between the listeners and the handler. The commands

            app.eventListeners.add("afterOpen", doBackup)

          and

            app.eventListeners.add("beforeSave", doBackup)

          create two distinct listeners based on the same handler.

          The first listener attaches doBackup to the event type "afterOpen",

          the second listener attaches doBackup to the event type "beforeSave".

           

          The event handler can easily deal with various event types, since an Event instance is always passed in as first argument.

           

          function doBackup( /*Event*/ ev ){ … }

           

          Each time doBackup is triggered it receives the current event to be managed. And that Event object has many interesting properties to make the handler as flexible as needed (ev.eventType, ev.target, etc.)

           

          @+

          Marc

          • 2. Re: double event for start up script
            Johnwhite Level 1

            Thank you Marc

            so that can set multi listeners for just one single handler.

             

            Regard

            John