Skip to main content
Inspiring
March 14, 2024
Answered

Turn off hyphenation except in stories that contain hyphenated words

  • March 14, 2024
  • 1 reply
  • 661 views

Hi everyone,

Is it possible to adapt the script below, so that it turns off hyphenation except for stories that contain hyphenated words? Basically, if all the story in a text frame is hyphenated (true), the script should turn it off (false) and ignore those text frames that contain hyphenated words.

var doc = app.activeDocument;

var stories = app.activeDocument.stories.everyItem().texts[0].hyphenation = false;
try{
var stories = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().hyphenation = false;
}catch(e){}

var PStyle = app.activeDocument.allParagraphStyles;  

for ( p = 1; p < PStyle.length; p++) PStyle

.hyphenation = false;


Thanks in advance,
Rogerio

This topic has been closed for replies.
Correct answer m1b

That's correct! 🙂


@Rogerio5C09 well I'm not sure what you're doing, but it sounds interesting. And I think this script will help.

- Mark

/**
 * Turn off hyphenation in any Story that has
 * every paragraph with hyphenation turned on.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/turn-off-hyphenation-except-in-stories-that-contain-hyphenated-words/m-p/14491538
 */
function main() {

    var doc = app.activeDocument,
        stories = doc.stories.everyItem().getElements();

    for (var i = 0, paras; i < stories.length; i++) {
        hyphenation = stories[i].paragraphs.everyItem().hyphenation;
        if (allTrue(hyphenation))
            stories[i].paragraphs.everyItem().hyphenation = false;
    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Manage hyphenation');


/**
* Returns true when all booleans are true.
* @param {Array<Boolean>} bools - array of booleans.
* @returns {Boolean}
*/
function allTrue(bools) {

    for (var i = 0; i < bools.length; i++)
        if (true !== bools[i])
            return false;

    return true;

};

1 reply

m1b
Community Expert
Community Expert
March 14, 2024

Hi @Rogerio5C09, so another way to say what you want is: to turn off hyphenation in every paragraph except where turning it off would change the line-breaks? Is that correct?

- Mark

Inspiring
March 14, 2024

Hi @m1b, thanks for checking! 🙂

Please turn off hyphenation in every paragraph in all stories/text frames that is set as "Hyphenate".


For those stories that contain hyphenated paragraphs among non-hyphenated ones, leave them as they are.

Would it be possible by any chance?

Thanks,
Rogerio'

m1b
Community Expert
Community Expert
March 14, 2024

So if I select all the text of a story, and the Hyphenate checkbox is ticked you want the script to turn hyphenation off in that story, but if it is indeterminate (the hyphen in the checkbox) then don't do anything?