1 Reply Latest reply on Feb 1, 2013 12:00 AM by Kasyan Servetsky

    Search for text and apply Object Style?

    Tricia Ho Level 1

      Hi,

       

      Is there a way to search for a word (eg Australia) and apply an Object Style to the Text Frame that the word is in?

       

      Cheers.

      Tricia

       

      Mac 10.7.5

      InDesign 8.0.1

        • 1. Re: Search for text and apply Object Style?
          Kasyan Servetsky Level 5

          This can be done by script. Type in the name of your style instead of My object style.

           

          Main();
          
          function Main() {
              var foundItem, foundItems;
              
              if (app.documents.length == 0) {
                  alert("Please open a document and try again.");
                  exit();
              }
          
              var doc = app.activeDocument;
              
              var objStyle = doc.objectStyles.itemByName("My object style"); // Type in the name of your style here
              if (objStyle == null) {
                  alert("The document doesn't have the required object style.");
                  exit();
              }
          
              app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
              app.findTextPreferences.findWhat = "Australia"; // The text to find
              foundItems = doc.findText();
              app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
              
              for (var i = 0; i < foundItems.length; i++) {
                  foundItem = foundItems[i];
                  if (foundItem.parentTextFrames[0].isValid) {
                      foundItem.parentTextFrames[0].appliedObjectStyle = objStyle;
                  }
              }
          }