1 Reply Latest reply on Jan 21, 2014 2:36 PM by Jump_Over

    Is it possible to srcipt something that reads text and make an appropriate image visible?

    ExperimentsWithDesign

      I have never written a script for indesign before so I am not really familiar with how it works

       

      Eessentailly, I have a text box that a user would be writting a state in. I then want the script to take that as input, and then make a hidden image of that state visible.

       

      Also, is it possible to have th script always running, or would the end user have to run it?

       

      Thank you!

        • 1. Re: Is it possible to srcipt something that reads text and make an appropriate image visible?
          Jump_Over Level 5

          Hi,

           

          It is possible using eventListeners. Look at example below and be awared that this is an example ONLY:

           

          To switch this ON run:

          #targetengine "session"
          var myDoc = app.activeDocument;
          myDoc.addEventListener("afterSelectionChanged", myDisplay);
          
          function myDisplay(myEvent){
               if(app.documents.length == 0) return;
               var curDoc = app.activeDocument;
               if(curDoc.selection.length == 0) return;
          
               var 
                    myInput = curDoc.textFrames.item("input"), 
                    myOutput = curDoc.pageItems.item("output");
          
               if (!myInput.isValid || !myOutput.isValid) return;
          
               if (myInput.contents == "ON") myOutput.visible = true; 
               else myOutput.visible = false;  
          }
          

           

          to switch this OFF run (or quit InDesign):

          app.activeDocument.eventListeners.everyItem().remove()
          

           

           

          Assumings:

          • input textFrame is named "input" (I mean in "Layer's Panel")
          • output pageItem is named "output"
          • type "ON" to make "output" visible

           

          Jarek