9 Replies Latest reply on Sep 10, 2008 2:23 PM by (Dylan)

    [JS] (CS3) eventListener & doScript

    CTC Imaging Level 1
      Hello everyone,

      Is it possible to create an eventListener, like "afterOpen" that would trigger a script file?
      In CS2, I wrote a few scripts that were managed by inEventScript Plug-in. We are upgrading to CS3 and this plug-in was not transported to CS3 since "eventListener" is available.
      So if possible, what is the syntax to execute the doScript within the Event Handler Function? It would not be app.doScript. So what?
      Thank you, Alex.
        • 1. Re: [JS] (CS3) eventListener & doScript
          Kasyan Servetsky Level 5
          Hi Alex,
          Here is an example:
          //-------------------------------
          #targetengine "session"
          myScriptPath = app.filePath + "/Scripts/Scripts Panel/ExportEachPageAsJPEG.jsx";
          var myFile = new File (myScriptPath);
          if (myFile.exists) {
          var myEventListener = app.addEventListener( "afterSave", myFile, false );
          }
          else {
          alert("File\"" + myFile.fsName + "\" has not been installed.");
          }
          //-------------------------------
          Kasyan
          • 2. Re: [JS] (CS3) eventListener & doScript
            CTC Imaging Level 1
            That's a start...

            What if I am using the user portion of the script panel?
            The dir changes for each user? What's the variable that addresses the user area? After that path we can add "/Scripts/Scripts Panel/ExportEachPageAsJPEG.jsx". Agreed?

            What's the difference between app.addEventListener(...) AND app.eventListeners.add(...)?

            And where is the CS3 Reference Guide, we used to have a CS2 one?

            Thanks, Alex.
            • 3. Re: [JS] (CS3) eventListener & doScript
              Kasyan Servetsky Level 5
              >And where is the CS3 Reference Guide, we used to have a CS2 one?

              http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/InDesignCS3_Scri ptingGuide_JS.pdf

              >What's the variable that addresses the user area?

              A path name can start with a tilde (~) to indicate the user's home directory. It corresponds to the platform’s HOME environment variable. (page 43 of JavaScript Tools Guide)
              http://www.adobe.com/devnet/bridge/pdfs/javascript_tools_guide_cs3.pdf

              e.g.
              var myFile = File ("~/Application Data/Adobe/InDesign/Version 5.0/Scripts/Scripts Panel/ExportEachPageAsJPEG.jsx");

              >What's the difference between app.addEventListener(...) AND app.eventListeners.add(...)?

              I am not sure, but they seem to be just two ways to do the same thing.
              I haven't delved deeply into how event listeners work — just took an example from the Scripting Guide and remade it to my needs.

              Kasyan
              • 4. Re: [JS] (CS3) eventListener & doScript
                CTC Imaging Level 1
                That's great. I'll b testing today.

                About the Reference, I already had the Scripting Guide. I was more looking at something similar to the CS2 reference where the syntax is layed out, instead of example. Looks like all eventListeners properties & methods are NOT listed...
                Thank you.
                • 5. Re: [JS] (CS3) eventListener & doScript
                  Level 1
                  Hi Alexandre,

                  The reference is now in the ExtendScript Toolkit. Choose "Adobe InDesign CS3 Object Model from the Help menu, and you'll see it. There is no separate PDF of the reference--though you can generate an HTML version (search the forum for posts by jongware and you'll find it).

                  The InDesign CS3 Scripting Guide does show all event listeners--try the chapter titled "Events".

                  Thanks,

                  Ole
                  • 6. Re: [JS] (CS3) eventListener & doScript
                    CTC Imaging Level 1
                    Thank you, I am sure that's what I am looking for.

                    I like dictionary like syntax. And I sure it is an over site regarding the scripting guide. I am/was kind in an hurry.

                    You know "Yesterday's" of someone else deadline.
                    • 7. Re: [JS] (CS3) eventListener & doScript
                      CTC Imaging Level 1
                      I am running into another issue now.

                      It does execute the script "afterOpen", but it is displaying my alert "No document open!!!" from my test: app.documents.lenght == 0.
                      So is there no Open Document altough it is an "after"???

                      The goal is to be able to execute some my regular script AND have have them attached to some events ("Open, Close, Copy & Paste). Or am I stuck to modify & include them in the STARTUP script. I know I can use event.parent to access the Document opened.

                      Also, are there events attached to pasting & copying (Before &/or after)?

                      Here is the Startup script.
                      --------------------------
                      #targetengine "session"

                      main();
                      function main()
                      {
                      var myScriptName = app.activeScript.fsName;
                      var myScriptPath = app.activeScript.path;
                      // var myPath = app.filePath + "/Scripts/Scripts Panel/~InEventScript/";
                      //** Number 0
                      var myFile = new File (myScriptPath+"/PrePressOPEN.jsx");
                      if (myFile.exists)
                      app.addEventListener( "afterOpen", myFile, false );
                      else
                      alert ("File:\n" + myFile.fsName + "\n...has NOT been Installed!!!");
                      }
                      • 8. Re: [JS] (CS3) eventListener & doScript
                        CTC Imaging Level 1
                        Good morning Olav,

                        Do you know how I could talk to regarding the EventListener Model?

                        There seems to be some "weird" behaviours, I would love to talk to someone about.

                        IE: "beforeClose", I would expect to have my event triggered BEFORE a "Save" dialog box inherent to the CLOSE action appears. My Event could also "take care of" that "Save", in other other it could become obscelete by the actions of my event.

                        Best regards, Alex.
                        • 9. Re: [JS] (CS3) eventListener & doScript
                          Level 1
                          I came here because I was having the same trouble in Applescript as this:
                          >It does execute the script "afterOpen", but it is displaying my alert "No document open!!!" from my test:

                          I spent a bit of time stuffing around and found out that my problem was that I was setting the variable myDoc to the name of the active document. I fixed this by setting the variable myDoc to the name of document 1.

                          I hope this helps, sorry I can't translate what I just said to Javascript.