I created a script that finds styles following another style and adds a Pink colour to the text. Which works for my needs as i can visually check them. It might be of use to you and if not - sure you have a new script that you might use some day.
// Check if a document is open
if (app.documents.length === 0) {
alert("Please open a document before running this script.");
} else {
var doc = app.activeDocument;
// Try to get the "Pink" swatch or create it if it doesn't exist
var PinkSwatch;
try {
PinkSwatch = doc.swatches.itemByName("Pink");
// If it exists, just skip the creation part
PinkSwatch.name; // Access to confirm existence (does nothing if it exists)
} catch (e) {
// If "Pink" swatch doesn't exist, create it
PinkSwatch = doc.colors.add({
name: "Pink",
model: ColorModel.process,
colorValue: [0, 100, 0, 0] // CMYK value for Pink (Magenta)
});
// We won't add it to the swatches, just use it directly
}
// Create a dialog window
var dlg = new Window("dialog", "Find Consecutive Styles");
dlg.orientation = "column";
dlg.alignChildren = ["fill", "top"];
// Add dropdowns for the first and second style selection
dlg.add("statictext", undefined, "Select the first paragraph style:");
var firstStyleDropdown = dlg.add("dropdownlist");
dlg.add("statictext", undefined, "Select the following paragraph style:");
var secondStyleDropdown = dlg.add("dropdownlist");
// Populate dropdowns with paragraph styles from the active document
var paraStyles = doc.allParagraphStyles;
for (var i = 0; i < paraStyles.length; i++) {
var item1 = firstStyleDropdown.add("item", paraStyles[i].name);
var item2 = secondStyleDropdown.add("item", paraStyles[i].name);
}
// Optionally, set defaults (for example, if you know the names)
firstStyleDropdown.selection = firstStyleDropdown.find("Subheading");
secondStyleDropdown.selection = secondStyleDropdown.find("Heading");
// Add the action buttons
var btnGroup = dlg.add("group");
btnGroup.alignment = "center";
var findBtn = btnGroup.add("button", undefined, "Find", {name:"ok"});
var cancelBtn = btnGroup.add("button", undefined, "Cancel", {name:"cancel"});
// Run the dialog
if (dlg.show() == 1) {
var styleOne = firstStyleDropdown.selection.text;
var styleTwo = secondStyleDropdown.selection.text;
var results = [];
// Loop through all stories and their paragraphs
for (var s = 0; s < doc.stories.length; s++) {
var story = doc.stories[s];
for (var p = 0; p < story.paragraphs.length - 1; p++) {
var para1 = story.paragraphs[p];
var para2 = story.paragraphs[p + 1];
// Check if para1 uses the first style and para2 uses the second style
if (para1.appliedParagraphStyle.name === styleOne &&
para2.appliedParagraphStyle.name === styleTwo) {
results.push("Story " + (s+1) + ", Paragraphs " + (p+1) + " and " + (p+2));
// For a visual cue, apply the PinkSwatch colour directly
para1.fillColor = PinkSwatch;
para2.fillColor = PinkSwatch;
}
}
}
// Provide feedback to the user
if (results.length > 0) {
alert("Found " + results.length + " occurrence(s):\n" + results.join("\n"));
} else {
alert("No occurrences found where '" + styleOne + "' is immediately followed by '" + styleTwo + "'.");
}
}
}
... View more