Skip to main content
Inspiring
May 8, 2025
Answered

Texts in bold style

  • May 8, 2025
  • 1 reply
  • 594 views

Hi everyone,
I want to create a script that finds all block texts in bold style and changes the format of the first letter of every word found in bold.
My script is not working, and I don't have enough knowledge to correct it.
Please could you help me:

 

if (app.documents.length === 0) {
alert("Nenhum documento está aberto!");
} else {
var doc = app.activeDocument;

if (doc.stories.length === 0) {
alert("O documento não contém nenhuma história de texto!");
} else {
for (var i = 0; i < doc.stories.length; i++) {
var story = doc.stories[i];

for (var j = 0; j < story.paragraphs.length; j++) {
var para = story.paragraphs[j];

for (var k = 0; k < para.words.length; k++) {
var word = para.words[k];

if (word.characters.length > 0 && word.characters[0].appliedFont.fontStyleName.toLowerCase().includes("heavy")) {
word.characters[0].pointSize = 18;
}
}
}
}

alert("Texto no estilo Heavy encontrado e ajustado!");
}
}



Correct answer m1b

Hi @Sami Artur, I asked for an example, but I might not need it now—ChatGPT explained to me that Hebrew diacritics are found in a run of Unicode codepoints. If this is right, I've incorporated a regular expression into the script that seems to capture them. Let me know how it goes.

- Mark

/**
 * @file Big Hebrew Initials.js
 *
 * @author m1b
 * @version 2025-05-09
 * @discussion https://community.adobe.com/t5/indesign-discussions/texts-in-bold-style/m-p/15310286
 */
function main() {

    var fontStyleToMatch = "heavy";

    if (app.documents.length === 0)
        return alert("Nenhum documento está aberto!");

    var doc = app.activeDocument;

    if (doc.stories.length === 0)
        return alert("O documento não contém nenhuma história de texto!");

    // collect all the words in all the stories of the document
    var words = doc.stories.everyItem().words.everyItem().getElements();
    var counter = 0;

    // match first letter and any Hebrew diacritics
    var matcher = /^.[\u0591-\u05C7]*/;

    for (var i = 0, word, match; i < words.length; i++) {

        word = words[i];

        if (
            word.characters.length === 0
            || word.characters[0].appliedFont.fontStyleName.toLowerCase().indexOf(fontStyleToMatch) === -1
        )
            continue;

        // match using the regexp
        match = word.contents.match(matcher);

        // change the font size
        word.characters.itemByRange(0, match[0].length - 1).pointSize = 18;

        // keep count
        counter++;

    }

    alert("Texto no estilo Heavy encontrado e ajustado!\n(" + counter + " palavras ajustadas)");

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Big Hebrew Initials');

 

1 reply

m1b
Community Expert
Community Expert
May 8, 2025

Hi @Sami Artur, in ExtendScript (ES3) String has no "includes" method, but for this you can use "indexOf":

word.characters[0].appliedFont.fontStyleName.toLowerCase().indexOf("heavy") !== -1

- Mark 

 

P.S. for your learning... you can also structure your script like this:

function main() {

    if (app.documents.length === 0)
        return alert("Nenhum documento está aberto!");

    var doc = app.activeDocument;

    if (doc.stories.length === 0)
        return alert("O documento não contém nenhuma história de texto!");

    var words = doc.stories.everyItem().words.everyItem().getElements();
    var counter = 0;

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

        var word = words[i];

        if (
            word.characters.length === 0
            || word.characters[0].appliedFont.fontStyleName.toLowerCase().indexOf("heavy") === -1
        )
            continue;

        word.characters[0].pointSize = 18;
        counter++;

    }

    alert("Texto no estilo Heavy encontrado e ajustado!\n(" + counter + " palavras ajustadas)");

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Big Heavy Initials');
Inspiring
May 8, 2025

Thank you very much, Mark!
I still have a little problem,
The texts are in Hebrew.
The first letter changes to size 18, but the diacritical accents don't.
Is there a way to change the size of the diacritical accents in the first letter, too?

m1b
Community Expert
Community Expert
May 9, 2025

Thank you again Mark!
It worked like a charm!


Good to hear!