2 Replies Latest reply on May 12, 2017 11:39 AM by cbishop01

    Apply Text variable to selected text?

    cbishop01 Level 2

      Right now I have the Text variable where it will add to the document.  And i have it set to a shortcut so that way if i need it i can add it My question is. How can i make it apply to the text i have selected?

      var doc = app.activeDocument;
      var tvLn = doc.textVariables.item("L#Date");   
          !tvLn.isValid && tvLn = doc.textVariables.add({name:"L#Date", variableType:VariableTypes.CUSTOM_TEXT_TYPE});    
          tvLn.variableOptions.contents = String( getLDate() );
        
      function getLDate() { 
          var date = new Date();  
          var month = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];  
          var formatDate = ("/" + date.getFullYear()).substr(-2);  
              return month[date.getMonth()] +"/" + formatDate;  
       }