6 Replies Latest reply on Jul 30, 2012 12:43 PM by bduffy323

    eventListener. Copy/Paste detection. POSIBLE???

    thinkink_es

      It's posible a custom eventListener to detect copy and paste.

       

      myDocument.eventListeners.add("beforePaste", myBeforePasteFunction);

        • 1. Re: eventListener. Copy/Paste detection. POSIBLE???
          [Jongware] Most Valuable Participant

          "beforePaste" is not listed anywhere in the Help as a supported event. The current list is beforeClose, beforeDeactivate, beforeDelete, beforeDisplay, beforeEmbed, beforeExport, beforeImport, beforeInvoke, beforeMove, beforeNew, beforeOpen, beforePlace, beforePrint, beforeQuit, beforeRevert, beforeSave, beforeSaveACopy, beforeSaveAs, befureUnembed, and beforeUpdate.

           

          See http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_Event.html for the complete list of events (CS5.5, but it seems CS6 has changed nothing). Note that not all events are applicable to all objects. Select one of the objects in the "parent" list to see which ones are supported for that. If an object supports events, these are listed under the sub-heading "Class", below "Properties".

           

          See for example http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_Link.html. This one contains "AFTER_DELETE" and "BEFORE_DELETE", but that only applies to links, and not to any other object such as text or pages.

          1 person found this helpful
          • 2. Re: eventListener. Copy/Paste detection. POSIBLE???
            Marijan Tompa [tomaxxi] Level 4

            You can monitor copy/paste by attaching event listeners to menu items of "Copy" and "Paste" commands.

             

            Something like this:

             

            #targetengine "tomaxxiTEST"
            
            ( function () {
                
                main ();
                
                function main () {
                    var
                        beforeCopy = app.menuActions.itemByID ( 270 ).addEventListener ( "beforeInvoke", eventHandler ), // COPY
                        afterCopy = app.menuActions.itemByID ( 270 ).addEventListener ( "afterInvoke", eventHandler ), // COPY
            
                        beforeCut = app.menuActions.itemByID ( 269 ).addEventListener ( "beforeInvoke", eventHandler ), // CUT
                        afterCut = app.menuActions.itemByID ( 269 ).addEventListener ( "afterInvoke", eventHandler ), // CUT
            
                        beforeClear = app.menuActions.itemByID ( 272 ).addEventListener ( "beforeInvoke", eventHandler ), // CLEAR
                        afterClear = app.menuActions.itemByID ( 272 ).addEventListener ( "afterInvoke", eventHandler ), // CLEAR
            
                        beforePaste = app.menuActions.itemByID ( 271 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE
                        afterPaste = app.menuActions.itemByID ( 271 ).addEventListener ( "afterInvoke", eventHandler ), // PASTE
            
                        beforePasteInPlace = app.menuActions.itemByID ( 273 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE IN PLACE
                        afterPasteInPlace = app.menuActions.itemByID ( 273 ).addEventListener ( "afterInvoke", eventHandler ), // PASTE IN PLACE
            
                        beforePasteInto = app.menuActions.itemByID ( 274 ).addEventListener ( "beforeInvoke", eventHandler ), // PASTE INTO
                        afterPasteInto = app.menuActions.itemByID ( 274 ).addEventListener ( "afterInvoke", eventHandler ); // PASTE INTO
                }
                
                function eventHandler ( evt ) {
                    alert ( evt.eventType + " | " + evt.currentTarget.name );
                }
            
            } ) ();
            

             

            Hope that helps.

             

            --

            Marijan (tomaxxi)

            http://tomaxxi.com

            1 person found this helpful
            • 3. Re: eventListener. Copy/Paste detection. POSIBLE???
              Marc Autret Level 4

              See also the 2nd snippet at:

               

              http://www.indiscripts.com/post/2010/02/how-to-create-your-own-indesign-menus

               

              which illustrates how to 'spy' the Paste action. The same approach can be used for Copy/Cut/etc. as Marijan showed.

               

              @+

              Marc

              1 person found this helpful
              • 4. Re: eventListener. Copy/Paste detection. POSIBLE???
                bduffy323 Level 1

                I know this is an older post, but where can I find the id's of the menu actions? Is there a list of them somewhere?

                 

                Thanks!

                • 5. Re: eventListener. Copy/Paste detection. POSIBLE???
                  Marijan Tompa [tomaxxi] Level 4

                  This will do the job:

                   

                  var
                      menuActions = app.menuActions,
                      menuActionsLength = menuActions.length,
                      menuActionsList = [],
                      newDoc = app.documents.add (),
                      docPage = newDoc.pages [ 0 ],
                      docMargins = docPage.marginPreferences,
                      actionsTextFrameBounds = [
                          docPage.bounds [ 0 ] + docMargins.top,
                          docPage.bounds [ 1 ] + docMargins.left,
                          docPage.bounds [ 2 ] - docMargins.bottom,
                          docPage.bounds [ 3 ] - docMargins.right, ],
                      actionsTextFrame = newDoc.pages [ 0 ].textFrames.add ( { geometricBounds : actionsTextFrameBounds } ),
                      actionsTable = actionsTextFrame.insertionPoints [ 0 ].tables.add ( { columnCount : 3, bodyRowCount : menuActionsLength } ),
                      i = 0;
                  
                  for ( i ; i < menuActionsLength ; i++ )
                      menuActionsList.push ( menuActions [ i ].name.toString () ),
                      menuActionsList.push ( menuActions [ i ].area.toString () ),
                      menuActionsList.push ( menuActions [ i ].id.toString () );
                  
                  actionsTable.contents = menuActionsList;
                  

                   

                  HTH.

                   

                  --

                  Marijan (tomaxxi)

                  http://tomaxxi.com

                  • 6. Re: eventListener. Copy/Paste detection. POSIBLE???
                    bduffy323 Level 1

                    Thank you! that did indeed get the job done.