main();
function main() {
if (app.documents.length > 0) {
var story, containers, container,
doc = app.activeDocument,
stories = doc.stories;
try {
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("GREEN PARA STYLE FIRST ON BLOCK");
app.changeTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("GREEN PARA STYLE");
doc.changeText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
}
catch(err) {
$.writeln(err.message + ", line: " + err.line);
}
for (var i = 0; i < stories.length; i++) {
story = stories;
containers = story.textContainers;
if (containers.length > 1) { // process only chained text blocks
for (var j = 0; j < containers.length; j++) {
container = containers;
if (container.appliedObjectStyle.name == "GREEN TEXT BLOCK") {
try { // if the style or the 1st paragraph is missing, write error message to console and continue
container.paragraphs[0].appliedParagraphStyle = doc.paragraphStyles.item("GREEN PARA STYLE FIRST ON BLOCK");
}
catch(err) {
$.writeln(err.message + ", line: " + err.line);
}
}
}
}
}
}
else {
alert("Please open a document and try again.", "Error", true);
}
}