Skip navigation
Currently Being Moderated

Search for string in paragraph and apply a new character style?

Jul 27, 2012 3:37 PM

Tags: #and #text #of #style #find_string #change_its_character

I'm searching for a way to find a specific string in a specific text frame and make it bold. so my thought was to search and then apply a character style from my template doc. I thought this would work, but I went wrong somewhere.


newDoc is my document. 


//something like

var Bios = "Representative Biography:\r want to leave this text normal.";

var myTextFrameBios = newDoc.pages.item(i).textFrames.add({geometricBounds:[4.5277, 2.36, 8.625, 5.375], contents:Bios});

var myTextObjectBios = myTextFrameBios.parentStory.texts.item(0);


// IS THIS CONFLICTING with my change below? Can I apply a character style within a par styled frame?

myTextObjectBios.appliedParagraphStyle = newDoc.paragraphStyles.item("CompanyProfile");



                                                  //Clear the find/change preferences.

                                                app.findGrepPreferences = NothingEnum.nothing;

                                                app.changeGrepPreferences = NothingEnum.nothing;

                                                app.findTextPreferences.findWhat = "Representative Biography:";

                                                app.changeTextPreferences.changeTo = "Representative Biography:";



                                                app.findGrepPreferences.appliedCharacterStyle = newDoc.characterStyles.item("BoldBioHead");

                                                // Perform the operation



                                                app.findGrepPreferences = NothingEnum.nothing;

                                                app.changeGrepPreferences = NothingEnum.nothing;

  • Currently Being Moderated
    Jul 28, 2012 11:35 AM   in reply to caseyctg

    @caseyctg – If you want to apply a character style to a text object in a specific text frame, you could restrict the scope of your script to that specific text frame:


    Example with the variable "myTextFrame" you have to define before:




    Btw.: you are doing a text search and clearing your GREP find/change preferences at the start of the snippet? Why is that?


    You could do a:


    app.changeTextPreferences = app.findTextPreferences = NothingEnum.nothing;




    app.changeTextPreferences = app.findTextPreferences = null;


    set before the search and after the change, if you want to be on the safe side…



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points