I’m new to scripting, I read a book, tried to follow but … I failed.
The script I wanted to write is soo simple but I don’t get it. Maybe someone can help me.
I want to format the paragraph following of certain headline-formats. So I need the script to check every paragraph of the active story. And if a paragraph has one of the headline formats, the next paragraph should become the format “no-indent”.
I need a “for” and an inserted “if”, but to name the right variables and to find the right objects is my problem.
I tried to adjust this script
#target InDesign
var _dok = app.activeDocument;
var _allPages = _dok.pages;
for (var i = 0; i < _allPages.length; i++) {
var _page = _allPages[i];
if (_page.textFrames.length > 0) {
var _tf = _page.textFrames[0];
var _firstPara = _tf.paragraphs[0];
if (_firstPara .appliedParagraphStyle.name == “h1”) {
_tf.paragraphs.nextItem(_firstPara ).appliedParagraphStyle = “no-indent”;
}
}
}
Because I need only the selected story and I wanted to integrate a general variable like this:
var _pSName = .appliedParagraphStyle.name;
to start:
if ( _pSName == “h1” || _pSName == “h2”) {
And I read that “nextParagraph” is better for long text than “nextItem”.
Can anybody rearrange the code pieces to a running script?
Thanks
Jeldrik