4 Replies Latest reply on Sep 4, 2013 5:25 AM by Marc Autret

    How to capture document changes using Javascript

    gopaljay78 Level 1

      Hi,

       

      Can anyone help me on the below request.

       

      Is it possible to capture document change event through Javascript. 

       

      For example,

      If i delete a word, then the event should be triggered and alert should be shown as "Word is deleted"

      If i make a word as Bold style, then the event should be triggered and alert should be shows as "Formatting changed".

       

      Thanks,

      Gopal

        • 2. Re: How to capture document changes using Javascript
          Vamitul Level 4

          sort of yes.

          have a look at indesign's events, particulary: AFTER_SELECTION_ATTRIBUTE_CHANGED and AFTER_SELECTION_CHANGED

          • 3. Re: How to capture document changes using Javascript
            Pickory Level 3

            Hello,

             

            In the plugin SDK there is a very nice example.

             

            ========================================

            //AfterSelectionAttributeChanged.jsx

            //An InDesign CS5 JavaScript

            //

            //Shows how to detect changes to the attributes of the selection. In this example,

            //we'll check the fill and stroke color of the selection. If either property has been

            //set to the "Registration" color, we'll display an alert when/if the attributes

            //of the selection change.

            #targetengine "session"

            main();

            function main(){

                      mySetup();

                      mySnippet();

                      myTeardown();

            }

            function mySetup(){

            }

            function mySnippet(){

                      //Add an event listener that checks the color of the selection.

                      //<fragment>

                      var myDocument = app.documents.add();

                      myDocument.eventListeners.add("afterSelectionAttributeChanged", myCheckForRegistration);

                      //</fragment>

            }

            function myTeardown(){

            }

            //<fragment>

            function myCheckForRegistration(myEvent){

                      var myRegistrationSwatchUsed = false;

                      if(app.selection.length != 0){

                                for(var myCounter = 0; myCounter < app.selection.length; myCounter++){

                                          if(

                                                    (

                                                              app.documents.item(0).selection[myCounter].fillColor == app.documents.item(0).swatches.item("Registration")

                                                    )

                                                    ||

                                                    (

                                                              app.documents.item(0).selection[myCounter].strokeColor == app.documents.item(0).swatches.item("Registration")

                                                    )

                                          ){

                                                    myRegistrationSwatchUsed = true;

                                          }

                                }

                      }

                      if(myRegistrationSwatchUsed == true){

                                alert("The Registration swatch is applied to some of the\robjects in the selection. Did you really intend to apply this swatch?");

                      }

            }

            //</fragment>