6 Replies Latest reply on Oct 5, 2010 5:54 AM by Kasyan Servetsky

    [JS] [CS4] afterOpen event query

    Skempy Level 1

      Hi,

       

      Am I right in thinking that

       

      var myEventListener = app.addEventListener("afterOpen", copyItem, false);

       

       

      function copyItem(myEvent) {

       

      myDoc = myEvent.parent

      myDoc.pageItems.item("copy").select()
      app.copy()

       

      }

       

      doesn't work because myDoc doesn't yet exist in a window?

       

      If so, is there any other way to get a labelled object into the clipboard for use in a grep find change?

       

      Thanks

       

      Simon Kemp.

        • 1. Re: [JS] [CS4] afterOpen event query
          Kasyan Servetsky Level 5

          Try

          var myDoc = app.documents[0];

          instead of

          myDoc = myEvent.parent

           

          (I haven't tested it)

           

          Kasyan

          • 2. Re: [JS] [CS4] afterOpen event query
            Harbs. Level 6

            It's probably not possible.

             

            You can't do UI specific stuff without a window open...

             

            It might be possible using AppleScript or VB, but I doubt it...

             

            If you are using CS5, you can try to add an idle event listener on docOpen, and do your work in that event. If you can get this to work, don't forget to remove the idle event handler afterwards!!!

             

            Harbs

            • 3. Re: [JS] [CS4] afterOpen event query
              Skempy Level 1

              Kasyan, Harbs,

               

              Thank you both for you replies. Unfortunately no CS5 yet.

               

               

               

              Simon.

              • 4. Re: [JS] [CS4] afterOpen event query
                Kasyan Servetsky Level 5

                This can be easily achieved with APID Toolkit:

                if (theItem.eventCode == "docLoaded") {
                     try {
                          var gDoc = app.activeDocument;
                          gDoc.pageItems.item("copy").select();
                          app.copy();
                     }
                     catch(err) {}
                }

                Event Filter: docLoaded

                 

                I wonder why the following code works then:

                #target indesign
                #targetengine "MyEngine"

                var myEventListener = app.eventListeners.add("afterOpen", myDocOpen, false);

                function myDocOpen(myEvent)
                {
                     var myDoc = app.documents[0];
                     var myLink = myDoc.links[0];
                     var myFile = new File("/C/Test.pdf");
                     if (myFile.exists) {
                          myLink.relink(myFile);
                     }
                }

                You can also add pages using afterOpen event -- but select and copy doesn't work

                 

                Kasyan

                1 person found this helpful
                • 5. Re: [JS] [CS4] afterOpen event query
                  Skempy Level 1

                  Thanks Kasyan,

                   

                  I am going to have a look at Rorohiko's APID Developer Toolkit but I would need to deploy the ToolAssistant on about 60 workstations and currently have no budget.

                   

                  If I can develop a working solution using this though, a budget might become available.

                   

                   

                  Thanks.

                  • 6. Re: [JS] [CS4] afterOpen event query
                    Kasyan Servetsky Level 5

                    but I would need to deploy the ToolAssistant on about 60 workstations and currently have no budget.

                    To develop scripted plug-ins you need APID Toolkit — $149, to use such plug-ins you need only APID ToolAssistant — $25 per seat, if you buy in bundle it's even cheaper: 10 — $19.90, 100 — $15.99, 1000 — $8.10.

                     

                    Anyway you can download both demo versions and test them for 20 days and decide if you need them or not.

                     

                    Kasyan