0

I have here a text in InDesign:

Hello (World),
this (nonsense) text
nobody (needs, right?).

With my jsx script I want to select the last match with brackets (needs, right?). But this result is formatted with regular and italic (needs is italic and the rest is regular). But I only want to change the regular style.

The part in my script looks like this:

function myFindGrep(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle){
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = mySearchString;
    app.findGrepPreferences.fontStyle = mySearchStyle;
    app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle);
    var myFoundItems = myObject.changeGrep();
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences = NothingEnum.nothing;
}

myFindGrep(selText.paragraphs.item(x), "\(.+?\)", "Regular", "Meist genutzte", "Zitat Regular");

When I apply this, it change my hole selection except the italic Text...

Is there a way to fix this?

jb_alvarado
  • 169
  • 3
  • 11

1 Answers1

0

I had to modify my function, to do a second grep:

function myFindQuote(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle) {
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = mySearchString;
    var myFoundItems = myObject.findGrep();

    for (var i = 0; i < myFoundItems.length; i++) {
        app.changeGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences = NothingEnum.nothing;
        app.findGrepPreferences.fontStyle = mySearchStyle;
        app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle);
        myFoundItems[i].changeGrep();
    }
}
jb_alvarado
  • 169
  • 3
  • 11