Skip to main content
Sayed Ali Mousawi
Known Participant
July 4, 2019
Answered

Select text based on character style or paragraph style

  • July 4, 2019
  • 3 replies
  • 1570 views

Hi Everyone !

i wrote this script with mr.[Jongware]​'s Help:

app.selection[0].appliedCharacterStyle = "R";

app.selection[0].insertionPoints[-1].appliedCharacterStyle = "Q";

app.selection[0].insertionPoints[-1].contents = ' (';

app.selection[0].insertionPoints[0].appliedCharacterStyle = "Q";

app.selection[0].insertionPoints[0].contents = ') ';

this is for a selected text,

Now i need to select all texts with a specific character style then execute this script. to apply changes all at once.

thank you very much.

This topic has been closed for replies.
Correct answer Manan Joshi

I don't understand the exact thing that you are trying to solve, before we get into specifics could you try the following code and see if that is what you want

app.findGrepPreferences = null

app.findGrepPreferences.appliedCharacterStyle = "W";

var found = app.activeDocument.findGrep(true)

for (i = 0; i < found.length; i++)

{

    found.appliedCharacterStyle = "R";

    found.insertionPoints[-1].appliedCharacterStyle = "Q";

    found.insertionPoints[-1].contents = ' ﴾';

    found.insertionPoints[0].appliedCharacterStyle = "Q";

    found.insertionPoints[0].contents = '﴿ ';

}

-Manan

3 replies

Sunil Yadav
Legend
July 5, 2019

Hi @https://forums.adobe.com/people/sayed%20alim9773784 ,

Please be more specific with the requirement of help that you are looking for.

Then there might be possibility of getting better help.

Best

Sunil

Community Expert
July 5, 2019

Hi Sayed,

The following code will find the text with a particular character style applied

app.findGrepPreferences = null

app.findGrepPreferences.appliedCharacterStyle = "Name_of_the_character_style"; //Change it as per your character style

var found = app.activeDocument.findGrep(true)

for (i = 0; i < found.length; i++){

    //found is the text which has the character style applied, so you can plugin your code in this for loop

    alert(found)

}

app.findGrepPreferences = null

-Manan

-Manan
Sayed Ali Mousawi
Known Participant
July 5, 2019

Hi Manan, Thank you,

but my code is based on selected text , and this is combined code that is not working.

app.findGrepPreferences = null 

app.findGrepPreferences.appliedCharacterStyle = "W";

var found = app.activeDocument.findGrep(true) 

for (i = 0; i < found.length; i++)

app.selection[0].appliedCharacterStyle = "R";

app.selection[0].insertionPoints[-1].appliedCharacterStyle = "Q";

app.selection[0].insertionPoints[-1].contents = ' ﴾';

app.selection[0].insertionPoints[0].appliedCharacterStyle = "Q";

app.selection[0].insertionPoints[0].contents = '﴿ ';

Manan JoshiCommunity ExpertCorrect answer
Community Expert
July 5, 2019

I don't understand the exact thing that you are trying to solve, before we get into specifics could you try the following code and see if that is what you want

app.findGrepPreferences = null

app.findGrepPreferences.appliedCharacterStyle = "W";

var found = app.activeDocument.findGrep(true)

for (i = 0; i < found.length; i++)

{

    found.appliedCharacterStyle = "R";

    found.insertionPoints[-1].appliedCharacterStyle = "Q";

    found.insertionPoints[-1].contents = ' ﴾';

    found.insertionPoints[0].appliedCharacterStyle = "Q";

    found.insertionPoints[0].contents = '﴿ ';

}

-Manan

-Manan
Anantha Prabu G
Legend
July 4, 2019
Design smarter, faster, and bolder with InDesign scripting.
Sayed Ali Mousawi
Known Participant
July 4, 2019

No Man! that's not what i'm looking for.

Anantha Prabu G
Legend
July 4, 2019

Hi,

I assume you need to insert the brackets "(" and ")" to applied character style throughout the document at once. Am I right? If wrong, please provide screenshots before and after process?

Thanks,

Prabu G

Design smarter, faster, and bolder with InDesign scripting.