2 Replies Latest reply on Dec 14, 2016 8:20 AM by Laubender

    How to double click on a text-frame and launch a script?

    Bill McLean

      I'm been searching for how to hook the double click event for a text-frame to launch a script.

       

      I working on an application that extends InDesign to solve a very specific problem domain. Each object is represented as a text-frame. By double clicking the text-frame, it will launch a script that allows you to edit the object represented by the text-frame. The object data is encoded into XML where a single instance of the XML data is associated with the text-frame.

       

      Thanks in advance

        • 1. Re: How to double click on a text-frame and launch a script?
          Marc Autret Level 4

          Hi Bill,

           

          Might we fake it?

           

          #targetengine FakeDblClickHandler
          
          // YOUR HANDLER COMES HERE
          // ---
          function onTextFrameDblClick(/*TextFrame*/target)
          {
              alert( "You have just double-clicked " + target );
              // etc.
          };
          
          const checkDblClick = function F(/*IdleEvent*/ev,  o,t)
          // -----------------------------------------------
          {
              (o=(o=app.properties.selection) && (1==o.length) && o[0]);
              t = +ev.timeStamp;
              o instanceof TextFrame ? (F.Q = t) : (t -= F.Q||0);
          
              if( t < 120 && o instanceof InsertionPoint )
              {
                  onTextFrameDblClick(o.parentTextFrames[0]);
              }
          };
          
          (function(tasks,name,rate,callback)    
          // -----------------------------------------------
          // Register the IdleTask
          {    
              var t = tasks.itemByName(name);    
              if( t.isValid )  
              {  
                  t.eventListeners.everyItem().remove();  
                  t.remove();  
              }    
              tasks.add({name:name, sleep:rate})  
                 .addEventListener(IdleEvent.ON_IDLE, callback, false);    
          
          })(app.idleTasks,$.engineName,15,checkDblClick);
          

           

          Purely experimental, of course ;-)

           

          Best,

          Marc

          1 person found this helpful
          • 2. Re: How to double click on a text-frame and launch a script?
            Laubender Adobe Community Professional & MVP

            Hi Marc and Bill,

            I'm not sure what is asked here.

             

            My interpretation:

            The user is supposed to double-click a text frame to run a script or a function that lurks in memory provided by a startup-script.

            Guess, yes. First I thought about a solution based on a selectionChanged event.

             

            Now Marc is working with an IdleEvent—very nice–by defining a double-click as a sequence of clicks less than 120 milliseconds.

            Cool.

             

            I tested Marc's code and see a potential problem concerning implementation:

             

            Supposed we have two text frames on a page with functional code.

            Nothing is selected.

            The Selection tool is the current tool.

             

            The user is double-clicking the first text frame.

            The Text tool is the current tool now.
            Code is running (Marc's alert is showing up).

             

            All is good so far.

            But now the user turns to the next text frame:

             

            Does a double-click.

            The Text tool is still the current tool.

            Code is not running. Alert is not showing.

             

            One solution could be, that the activated code will switch the current tool to the Selection tool:

             

            function onTextFrameDblClick(/*TextFrame*/target) 
            { 
               app.toolBoxTools.currentTool = UITools.SELECTION_TOOL; 
               alert( "You have just double-clicked " + target ); 
                // etc.
                
            };
            

             

            But after testing that, the alert did not come up sometimes.

            So I decided to deselect the selection as well. And finally that worked better.

             

            Though, sometimes it did not work so I had to press ESC to select the frame with the Selection Tool, had to wait perhaps a second before trying another double-click on the text frame to activate the alert.

             

            // YOUR HANDLER COMES HERE  
            // ---  
            function onTextFrameDblClick(/*TextFrame*/target)  
            {  
                app.select(null);
                app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
                
                alert( "You have just double-clicked " + target );  
                // etc.
                
            }; 
            

             

             

            Regards,
            Uwe