/ Id-Extras Forum / AfterOpen Script

  • Author
  • #6172 Reply
    Wonderboy
    Participant

      Does anyone know how to use afterOpen?

      I would like to have it so whenever someone opens a specific indesign file, a dialog pops up asking them questions and the user can make selections and input text.

      im having trouble getting the a simple alert to pop up automatically after opening using afterOpen

      Any idea?

      #targetengine “main”

      app.addEventListener(‘afterOpen’, function(myEvent) {

      if (myEvent.target.constructor.name !== ‘new sample’) {
      return;
      }

      var myDoc = myEvent.target;
      // Continue on with your code from here
      alert(“testing”)
      })

      #6325 Reply
      ~~Ariel~~
      Participant

        This seems to work for me, when an existing document is opened. It shows the number of pages in the document. I changed the name of the #targetengine, though, to make it persistent.

        Code:
        #targetengine MyOpenEvent

        app.addEventListener(‘afterOpen’, myOpenFunction);

        function myOpenFunction(myEvent){
        if(myEvent.target instanceof Document){
        alert(myEvent.target.pages.length);
        }
        }

        Does that help?
        Ariel

        #6326 Reply
        Wonderboy
        Participant

          yes this is what i needed. thanks for the help

          #6327 Reply
          Wonderboy
          Participant

            i went down a rabbit hole that is over my head.

            how would i make a dialog window pop up within this function? i got an alert that tells me the document name, but im trying to get a dialog to pop up as well. would that happen within the myOpenFunction? would it call on another script?

            #6328 Reply
            ~~Ariel~~
            Participant

              Do you know how to build a dialog with ScriptUI? (There’s also a simpler way of making dialogs, but I would recommend getting to know ScriptUI.)
              Once you’ve got a working dialog, just stick it in the myOpenFunction and it will pop up whenever a doc is opened.
              (If you just need really simple user input, there’s also the prompt() command.)

              #6329 Reply
              Wonderboy
              Participant

                yeah i used it to make a dialog box. it wouldn’t work at first but after messing around with it i finally got it to work. thanks again for your help

              Viewing 6 posts - 1 through 6 (of 6 total)
              Reply To: Reply #6329 in AfterOpen Script
              Your information: