6 Replies Latest reply on Aug 30, 2011 1:12 PM by Dirk Becker

    [AS] Event listener is called 2x?

    SuperMacGuy Level 2

      I'm testing some event listener scripts. I have a script that is AfterOpen that would do something after a doc is opened. But when I am testing this, the script is called twice. Does anyone have any experience with this? Why would this happen, or how do we stop it from happening? Can it be run only 1 time? I was opening a document via double click and open dialog also, same effect, it's run 2x.

        • 1. Re: [AS] Event listener is called 2x?
          Bob Stucky Adobe Employee

          With ID many of the events are fired multiple times for a given user action (say opening a document). If you look at the target of the event, you should see that the events are being fired with different targets.


          If you are using or have access to Extension Builder, there's a sample application called Event Watcher. That extension allows you to register for ID, PS, AI events. The panel shows you what events fire when.



          • 2. Re: [AS] Event listener is called 2x?
            Harbs. Level 6

            Hey Bob,


            I think the AS was Applescript and not Actionscript...



            • 3. Re: [AS] Event listener is called 2x?
              Bob Stucky Adobe Employee

              I figured that as well given the forum.


              I mentioned the Extension Builder watcher extension only because it is the only one I know of that'll easily show the when's, where's, and how's of event dispatching.



              • 4. Re: [AS] Event listener is called 2x?
                SuperMacGuy Level 2

                Thanks Bob. But, then really how are event listeners reliable? If InDesign's AfterOpen fires 2 (or more) times, how can an action be reliable if it should only activate 1 time, or writes a text log, or even displays a dialog to a user too many times?


                My goal is to either make a text file or write to a text file when a document is opened. But if this script runs 2x then for every document action I'll get 2 log entries, and that sort of invalidates the data as being reasonably reliable.


                Is there something I'm not understanding about event listeners? Is there a way to filter them? A way to suppress secondary firings?


                I don't have Extension Builder (nor access to the Enterprise Dev program at my work).

                • 5. Re: [AS] Event listener is called 2x?
                  SuperMacGuy Level 2

                  I found I can filter events by their parent to know who's firing it. Sometimes it's the document sometimes it's a window.

                  • 6. Re: [AS] Event listener is called 2x?
                    Dirk Becker Level 4

                    Make sure your testing also covers situations where InDesign documents are opened temporarily / under the hood, for example the source documents for style imports (via style panel flyout menu), or when you place a document, export a PDF from a book referencing the document. I'm not sure whether all of them trigger the event, but at least the styles do it!