2 Replies Latest reply on Jul 26, 2013 12:05 PM by RobertKyle

    Can beforeInvoke event listener cancel the Paste event?

    RobertKyle Level 2

      I'm contemplating an event listener script to prevent users from using Paste when they should be using Paste without formatting. I've gotten as far setting up the event listener and detecting the conditions under which we want Paste without formatting to be used, but I'm stuck on how to prevent the Paste from happening. The only idea I have to let it happen, then undo it and immediately invoke Paste without formatting. Is there a more efficient way?

        • 2. Re: Can beforeInvoke event listener cancel the Paste event?
          RobertKyle Level 2

          I saw that thread (and borrowed heavily from it) before I posted. I've got no problem detecting the Paste event; I'm puzzled about the handler that fires after Paste is detected.


          Here's what I have so far:


          #targetengine "session"


          var beforePaste = app.menuActions.itemByID ( 271 ).addEventListener ( "beforeInvoke", eventHandler );// PASTE

          var afterPaste = app.menuActions.itemByID ( 271 ).addEventListener ( "afterInvoke", eventHandler ); // PASTE

          var redoPaste = false;


          function eventHandler ( evt ) {

              if (evt.eventType == "beforeInvoke") {

                  redoPaste = false;

                  var elementType = app.selection[0].parentStory.storyTitle;

                  if (elementType !="Body") {

                  var theAnswer = confirm ("You're pasting into a " + elementType + " element and may wipe out the styles applied to that element. Do you want to use Paste without formatting instead?",false,"Think about it")

                      if (theAnswer == true){

                          redoPaste = true;


                  } // element == "Body"

              } else { // afterInvoke

                  if (redoPaste == true) {







          Note: This script actually runs in InCopy where storyTitle might be a string like "Caption", "Headline" or "Body." The point is that the Caption and Headline fields already have styles assigned to them, and we don't want users to Paste in the wrong style.So the beforePaste event sets a flag based on the current selection.When the flag is up, the afterPaste event unDoes the Paste and calls app.pasteWithoutFormatting().


          Seems to me that this process might be more robust if I could cancel the Paste event rather than unDoing it.