Reset One Attribute of an InDesign Paragraph Style to Its Based On Style

This article is also available as a short video on YouTube: InDesign Paragraph Style Not Updating? Find What the Child Style Overrides

A question on Graphic Design Stack Exchange describes a Caption paragraph style with about fifteen settings of its own. The asker wants to remove just one of them, the font style, so that Caption takes it from its Based On style again. There is no "None" in the menu, and clearing a field such as Size gives an Invalid Entry error. One workaround offered there was to take a screenshot, click Reset To Base, and type the other fourteen settings back in. The accepted answer says that if you set the attribute to the same value as the Based On style, later changes to the parent carry over to the child.

I tested that answer in InDesign 21.6. It works. I also found a case where it does not show you anything to fix, and wrote a script that lists what a style sets itself and resets the ones you pick.

Why a child style stops following its parent

A paragraph style based on another style takes every setting from the parent except the ones it sets itself. Open the child's Paragraph Style Options and look at Style Settings on the General page. It reads like this:

Body + next: [Same style] + Italic + size: 8 pt + space before: 0p6

Everything after "Body +" is set by Caption itself. ("next:" is the Next Style setting, which is not formatting.) If you change the font style in Body, Caption keeps Italic. This is one common reason a paragraph style seems to be "not working": the parent was changed and the child did not move.

(0p6 is 6 points written in picas. My test document used picas for spacing.)

Set it to the parent's value

The accepted answer is right. In my test, Body was Regular and Caption was Italic. I set Caption's Font Style to Regular in Paragraph Style Options. Italic disappeared from Style Settings. Then I set Body to Bold, and Caption became Bold too, while its Size stayed at 8 pt.

So once Caption's Font Style matched Body's, InDesign stopped keeping it in Caption. The script tests below found the same for the other settings I tried, including size, indents, alignment, tabs and GREP styles. Setting the parent's value is how you remove one attribute.

Reset To Base, the button at the right of Style Settings, removes all of them at once. After clicking it, Style Settings showed only "Body + next: [Same style]".

The setting you cannot see

This is the case the answer does not cover. Start again with Caption at Space Before 6 pt and Body at 0. Now change Body's Space Before to 6 pt. Both styles have the same value, and "space before" disappears from Caption's Style Settings.

Style Settings for Caption without space before after the parent was set to the same value
Body set to 6 pt too: space before is gone from Caption's Style Settings.

Caption still has its own 6 pt. When I changed Body to 9 pt, Caption stayed at 6 pt, and "space before: 0p6" came back in Style Settings.

Style Settings for Caption showing space before 0p6 again after the parent changed to 9 pt
Body changed to 9 pt: Caption still has its own 6 pt (0p6), and it is back in Style Settings.

In this test, Style Settings showed what differed from the parent at that moment, not everything the child set. Space Before disappeared from the summary while the values matched, but Caption kept its own value and did not follow Body's next change. In a template that has been edited for years, you cannot tell from the dialog which of these are waiting.

What the script shows

The script lists the formatting settings the selected style holds itself, with its value and the value it would get from its Based On style. Settings that match the parent right now are marked "same value". Next Style, Based On, keyboard shortcuts and export tags are left out.

Style overrides dialog for Caption listing Size 8 against 10 and Space Before 6 against 6 marked same value
The script's dialog for Caption. Space Before matches Body, but Caption still holds it.

Select one or more rows and click Reset Selected. The script gives each one the parent's value, then reads the style again and tells you how many are gone. Edit > Undo reverts the whole reset in one step. If the script reports an error, close the dialog and use Undo.

A few things to know about the list:

  • Names follow Paragraph Style Options where I mapped them, such as Size and Space Before. A setting that is not in my table is shown with its internal name split into words.
  • Some values are shown the way InDesign stores them: language as a code such as de_DE_2006, and alignment as CenterAlign. Sizes are in points.
  • Some settings are listed but marked "Style Options only". The bullet character is one: it is stored as a group of values, and the script does not reset it. Change those in Paragraph Style Options.
  • Tabs, nested styles, GREP styles and nested line styles are shown as a number of items. A child that removed all of the parent's GREP styles is listed with 0 items, because that empty list is also a setting of its own. If the parent's list later becomes empty too, the row disappears, and the child stays empty when the parent gets items again.
  • When you reset Font Family, InDesign also clears the child's own Font Style. After a reset, the script compares the settings you did not select with their earlier values, sets back any that changed, and tells you. Reset Font Style as well if you want both from the parent. A setting that matched the parent cannot be put back this way, because giving it the parent's value is what removes it, so the script only reports it.
  • It works for character styles too. Styles based on [No Paragraph Style] or [None] are not listed, because there is no parent to reset to.

How it reads the style

There is no scripting property that says whether a child sets an attribute or inherits it. Reading a property gives the value in effect, which is the same in both cases when the values match.

The exported IDML file does keep the difference. In Resources/Styles.xml, each style's entry has its name and other style information, plus the formatting settings it holds itself. Inherited settings are not in it. So the script exports the document to IDML in your temporary folder, reads Styles.xml, and tries to delete both, also when the export fails. If a file cannot be deleted, it tells you where it is. The document is not changed and does not need to be saved. On a 40-page test document I generated with about 300 paragraph styles, the export and reading took less than half a second.

To reset a setting, the script sets the child's value to the parent's. For tabs and the nested, GREP and line style lists, it reads the parent's items and copies them into the child. If copying fails, the script tries to put the child's own items back. If that also fails, close the dialog and use Undo. In my tests the child then stopped holding the list, and an item added to the parent later showed up in the child.

The script

Download StyleOverrides.jsx from GitHub, or copy the code below. The test script and its log are in the repository.

Save this as StyleOverrides.jsx in your Scripts folder and run it from the Scripts panel. If a paragraph is selected, the dialog opens on its paragraph style. If that style is not based on another style, the dialog says so and opens on the first style in the list. If you have not installed a script before, Your First InDesign Script shows where the folder is and what to watch for when pasting code into a text editor.

Show the full script
// StyleOverrides.jsx
// Lists the formatting settings a paragraph or character style holds itself
// (instead of taking them from its Based On style), including ones whose value
// happens to match the parent, and resets the ones you select to the Based On style.
//
// How it reads the style: the script exports the document to a temporary IDML
// file, reads Resources/Styles.xml, and deletes the temporary files. The
// document itself is not changed unless you click Reset Selected.
//
// Not listed: Next Style, Based On, shortcuts, export tags and other settings
// that are not formatting. Some listed settings (for example the bullet
// character) cannot be reset by this script; they are marked "Style Options only".
//
// Tested in InDesign 21.6 on Windows. Edit > Undo reverts a reset in one step.
// MIT License. Linguist Coder.

#target indesign

var SO_SKIP_ATTRS = {Self: 1, Name: 1, Imported: 1, NextStyle: 1, SplitDocument: 1, EmitCss: 1,
    StyleUniqueId: 1, IncludeClass: 1, ExtendedKeyboardShortcut: 1, EpubAriaRole: 1,
    EmptyNestedStyles: 1, EmptyLineStyles: 1, EmptyGrepStyles: 1, KeyboardShortcut: 1};
// An empty nested / GREP / line style list is recorded only as one of these flags.
var SO_EMPTY_FLAGS = {EmptyNestedStyles: "AllNestedStyles", EmptyGrepStyles: "AllGREPStyles",
    EmptyLineStyles: "AllLineStyles"};
var SO_SKIP_PROPS = {BasedOn: 1, PreviewColor: 1};
var SO_COLLECTIONS = {TabList: "tabStops", AllNestedStyles: "nestedStyles",
    AllGREPStyles: "nestedGrepStyles", AllLineStyles: "nestedLineStyles"};
var SO_COLLECTION_FIELDS = {
    tabStops: ["position", "alignment", "alignmentCharacter", "leader"],
    nestedStyles: ["appliedCharacterStyle", "delimiter", "inclusive", "repetition"],
    nestedGrepStyles: ["appliedCharacterStyle", "grepExpression"],
    nestedLineStyles: ["appliedCharacterStyle", "lineCount"]
};

// Problems met while removing temporary files, shown by the dialog.
var SO_CLEANUP_ERRORS = [];

function soKind(style) {
    return (style instanceof CharacterStyle) ? "Character" : "Paragraph";
}

function soDocOf(obj) {
    var p = obj;
    while (p && !(p instanceof Document)) p = p.parent;
    return p;
}

// Remove a folder and everything in it. Returns paths that could not be removed.
function soRemoveFolder(folder) {
    var failed = [];
    if (!folder.exists) return failed;
    var items = folder.getFiles();
    for (var i = 0; i < items.length; i++) {
        if (items[i] instanceof Folder) failed = failed.concat(soRemoveFolder(items[i]));
        else if (!items[i].remove()) failed.push(items[i].fsName);
    }
    if (!folder.remove()) failed.push(folder.fsName);
    return failed;
}

// Export the document to IDML in the temp folder and return Styles.xml as XML.
// The temporary files are removed whether or not the export or the reading worked.
function soReadStylesXml(doc) {
    var stamp = "style_overrides_" + new Date().getTime();
    var idml = new File(Folder.temp + "/" + stamp + ".idml");
    var dir = new Folder(Folder.temp + "/" + stamp);
    var txt = null;
    try {
        var oldLevel = app.scriptPreferences.userInteractionLevel;
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
        try {
            if (typeof SO_TEST_FAIL != "undefined" && SO_TEST_FAIL == "export") {
                idml.open("w"); idml.write("partial"); idml.close();
                throw new Error("test: export failed");
            }
            doc.exportFile(ExportFormat.INDESIGN_MARKUP, idml, false);
        } finally {
            app.scriptPreferences.userInteractionLevel = oldLevel;
        }
        if (typeof SO_TEST_FAIL != "undefined" && SO_TEST_FAIL == "unpack") throw new Error("test: unpack failed");
        app.unpackageUCF(idml, dir);
        var f = new File(dir.fsName + "/Resources/Styles.xml");
        f.encoding = "UTF-8";
        if (!f.open("r")) throw new Error("Could not open Styles.xml from the exported IDML.");
        txt = f.read();
        f.close();
    } finally {
        try { SO_CLEANUP_ERRORS = SO_CLEANUP_ERRORS.concat(soRemoveFolder(dir)); }
        catch (e1) { SO_CLEANUP_ERRORS.push(dir.fsName + ": " + e1); }
        try { if (idml.exists && !idml.remove()) SO_CLEANUP_ERRORS.push(idml.fsName); }
        catch (e2) { SO_CLEANUP_ERRORS.push(idml.fsName + ": " + e2); }
    }
    txt = txt.replace(/^\s*<\?xml[^>]*\?>/, "");
    // Keep whitespace inside values (GREP expressions, delimiters) exactly as stored.
    var oldWs = XML.ignoreWhitespace;
    XML.ignoreWhitespace = false;
    try { return new XML(txt); } finally { XML.ignoreWhitespace = oldWs; }
}

// In IDML a grouped style is named by its full path ("Group:Sub:Style"),
// with ":" and "\" inside each name escaped by a backslash.
function soIdmlName(style) {
    function esc(s) { return s.replace(/\\/g, "\\\\").replace(/:/g, "\\:"); }
    var parts = [esc(style.name)];
    var p = style.parent;
    while (p instanceof ParagraphStyleGroup || p instanceof CharacterStyleGroup) {
        parts.unshift(esc(p.name));
        p = p.parent;
    }
    return parts.join(":");
}

function soFindNode(xml, style) {
    var want = soIdmlName(style);
    var all = xml.descendants(soKind(style) + "Style");
    for (var i = 0; i < all.length(); i++) if (String(all[i].@Name) == want) return all[i];
    return null;
}

// BasedOn holds the parent's Self ("ParagraphStyle/Body"), except for the root
// default style, which is given as a bare "$ID/[No paragraph style]".
function soFindBySelf(xml, kind, self) {
    var all = xml.descendants(kind + "Style");
    var alt = kind + "Style/" + self;
    for (var i = 0; i < all.length(); i++) {
        var s = String(all[i].@Self);
        if (s == self || s == alt) return all[i];
    }
    return null;
}

function soCount(n) { return n + (n == 1 ? " item" : " items"); }

// IDML attribute name -> the label used in Paragraph / Character Style Options.
// Names not in this table are shown with spaces between words ("SpaceBefore" -> "Space Before").
var SO_UI_NAMES = {
    AppliedFont: "Font Family", FontStyle: "Font Style", PointSize: "Size", Leading: "Leading",
    KerningMethod: "Kerning", Tracking: "Tracking", Capitalization: "Case", Position: "Position",
    Underline: "Underline", StrikeThru: "Strikethrough", Ligatures: "Ligatures", NoBreak: "No Break",
    FillColor: "Character Color", FillTint: "Character Color Tint", StrokeColor: "Stroke Color",
    StrokeWeight: "Stroke Weight", HorizontalScale: "Horizontal Scale", VerticalScale: "Vertical Scale",
    BaselineShift: "Baseline Shift", Skew: "Skew (False Italic)", AppliedLanguage: "Language",
    Justification: "Alignment", LeftIndent: "Left Indent", RightIndent: "Right Indent",
    FirstLineIndent: "First Line Indent", LastLineIndent: "Last Line Indent",
    SpaceBefore: "Space Before", SpaceAfter: "Space After", AlignToBaseline: "Align to Grid",
    TabList: "Tabs", AllNestedStyles: "Nested Styles", AllGREPStyles: "GREP Styles",
    AllLineStyles: "Nested Line Styles", DropCapLines: "Drop Cap Lines",
    DropCapCharacters: "Drop Cap Characters", Hyphenation: "Hyphenate", Composer: "Composer",
    KeepWithNext: "Keep with Next Lines", KeepLinesTogether: "Keep Lines Together",
    KeepAllLinesTogether: "All Lines in Paragraph", KeepFirstLines: "Keep Lines at Start",
    KeepLastLines: "Keep Lines at End", StartParagraph: "Start Paragraph",
    RuleAbove: "Rule Above", RuleBelow: "Rule Below", RuleAboveLineWeight: "Rule Above Weight",
    RuleBelowLineWeight: "Rule Below Weight", RuleAboveColor: "Rule Above Color",
    RuleBelowColor: "Rule Below Color", RuleAboveOffset: "Rule Above Offset",
    RuleBelowOffset: "Rule Below Offset", BulletsAndNumberingListType: "List Type",
    BulletChar: "Bullet Character", AppliedNumberingList: "Numbering List",
    SpanColumnType: "Paragraph Layout", ParagraphShadingOn: "Paragraph Shading",
    ParagraphBorderOn: "Paragraph Border",
    OTFContextualAlternate: "OpenType Contextual Alternates", OTFDiscretionaryLigature: "OpenType Discretionary Ligatures"
};

function soUiName(key) {
    if (SO_UI_NAMES.hasOwnProperty(key)) return SO_UI_NAMES[key];
    return key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2");
}

// "Color/Red" -> "Red", "CharacterStyle/Emph" -> "Emph", "$ID/English: USA" -> "English: USA".
function soShowValue(v) {
    return String(v).replace(/^(Color|Swatch|Tint|Gradient|MixedInk|CharacterStyle|ParagraphStyle|NumberingList|Language)\//, "").replace(/^\$ID\//, "");
}

// Exact text of an element, attributes and children included, for comparing
// a child's setting with its parent's. Whitespace inside values is kept.
function soSig(x) {
    var s = String(x.name());
    var at = x.attributes();
    for (var i = 0; i < at.length(); i++) s += " " + at[i].name() + "=" + String(at[i]);
    var kids = x.elements();
    if (!kids.length()) return s + "=" + String(x.text());
    var parts = [];
    for (var k = 0; k < kids.length(); k++) parts.push(soSig(kids[k]));
    return s + "{" + parts.join("|") + "}";
}

// A setting stored as a record (attributes or child elements), such as BulletChar.
function soIsRecord(x) {
    if (x.elements().length()) return true;
    var at = x.attributes();
    for (var i = 0; i < at.length(); i++) if (String(at[i].name()) != "type") return true;
    return false;
}

function soRecordText(x) {
    var at = x.attributes(), parts = [];
    for (var i = 0; i < at.length(); i++) if (String(at[i].name()) != "type") parts.push(at[i].name() + "=" + String(at[i]));
    if (x.elements().length()) parts.push("(more settings)");
    return parts.join(", ");
}

// Settings stored on one style element.
// values[key] = text shown in the dialog, sigs[key] = text used to compare with the parent,
// records[key] = true for record settings (not reset by this script).
// emptyOnly[key] = true when an Empty...Styles="true" flag is the only record of a
// nested / GREP / line style list (the style has an explicitly empty list, or the
// list is empty all the way up; the caller tells these apart).
function soStored(node) {
    var out = {keys: [], values: {}, sigs: {}, emptyOnly: {}, records: {}};
    function put(k, v, sig) { out.keys.push(k); out.values[k] = v; out.sigs[k] = sig; }
    var attrs = node.attributes();
    for (var i = 0; i < attrs.length(); i++) {
        var n = String(attrs[i].name());
        if (SO_SKIP_ATTRS[n]) continue;
        put(n, String(attrs[i]), String(attrs[i]));
    }
    var props = node.child("Properties");
    if (props.length()) {
        var kids = props[0].elements();
        for (var j = 0; j < kids.length(); j++) {
            var pn = String(kids[j].name());
            if (SO_SKIP_PROPS[pn]) continue;
            if (SO_COLLECTIONS[pn]) {
                put(pn, soCount(kids[j].child("ListItem").length()), soSig(kids[j]));
            } else if (soIsRecord(kids[j])) {
                put(pn, soRecordText(kids[j]), soSig(kids[j]));
                out.records[pn] = true;
            } else {
                put(pn, String(kids[j].text()), soSig(kids[j]));
            }
        }
    }
    for (var e in SO_EMPTY_FLAGS) {
        var list = SO_EMPTY_FLAGS[e];
        if (String(node.attribute(e)) == "true" && !out.sigs.hasOwnProperty(list)) {
            put(list, soCount(0), "");
            out.emptyOnly[list] = true;
        }
    }
    return out;
}

function soBasedOnSelf(node) {
    var props = node.child("Properties");
    if (!props.length()) return null;
    var b = props[0].child("BasedOn");
    if (!b.length()) return null;
    var s = String(b[0].text());
    return s || null;
}

// What the style would get from its Based On chain for one key: {value, sig}.
function soParentValue(xml, kind, node, key) {
    var self = soBasedOnSelf(node);
    var guard = 0;
    while (self && guard++ < 50) {
        var pn = soFindBySelf(xml, kind, self);
        if (!pn) break;
        var st = soStored(pn);
        if (st.sigs.hasOwnProperty(key)) return {value: st.values[key], sig: st.sigs[key]};
        self = soBasedOnSelf(pn);
    }
    return SO_COLLECTIONS[key] ? {value: soCount(0), sig: ""} : {value: "(default)", sig: "(default)"};
}

// IDML name -> {name, writable} of the scripting property, or null.
// Matched without regard to case ("OTFHVKana" -> "otfHVKana").
function soProp(style, key) {
    if (SO_COLLECTIONS[key]) return {name: SO_COLLECTIONS[key], writable: true};
    var want = key.toLowerCase();
    var props = style.reflect.properties;
    for (var i = 0; i < props.length; i++) {
        if (props[i].name.toLowerCase() == want) return {name: props[i].name, writable: props[i].type != "readonly"};
    }
    return null;
}

// [No Paragraph Style] and [None] throw "Invalid request on a root style" when
// basedOn is read, so a throw also means "root".
function soIsRootStyle(style) {
    var b;
    try { b = style.basedOn; } catch (e) { return true; }
    return !b || typeof b == "string" || b.name == "[No Paragraph Style]" || b.name == "[None]";
}

// Main read function: list what the style holds itself.
// Returns [{key, label, prop, canReset, value, parentValue, sameAsParent}],
// or a string explaining why not.
function listOverrides(doc, style, xml) {
    if (soIsRootStyle(style)) return "\"" + style.name + "\" is not based on another style.";
    xml = xml || soReadStylesXml(doc);
    var node = soFindNode(xml, style);
    if (!node) return "Could not find \"" + style.name + "\" in the exported styles.";
    var kind = soKind(style);
    var st = soStored(node);
    var rows = [];
    for (var i = 0; i < st.keys.length; i++) {
        var k = st.keys[i];
        var pv = soParentValue(xml, kind, node, k);
        // An empty list only counts as held by this style when the parent's list is not empty.
        if (st.emptyOnly[k] && pv.sig == "") continue;
        var p = soProp(style, k);
        rows.push({key: k, label: soUiName(k), prop: p ? p.name : null,
            canReset: !!(p && p.writable && !st.records[k]),
            value: soShowValue(st.values[k]), parentValue: soShowValue(pv.value),
            sameAsParent: st.sigs[k] == pv.sig});
    }
    return rows;
}

function soReadItems(coll, fields) {
    var specs = [];
    for (var i = 0; i < coll.length; i++) {
        var spec = {};
        for (var f = 0; f < fields.length; f++) spec[fields[f]] = coll[i][fields[f]];
        specs.push(spec);
    }
    return specs;
}

function soReplaceItems(style, prop, specs) {
    // Remove one at a time from the end (everyItem().remove() fails on GREP styles).
    for (var r = style[prop].length - 1; r >= 0; r--) style[prop][r].remove();
    for (var s = 0; s < specs.length; s++) {
        if (typeof SO_TEST_FAIL != "undefined" && SO_TEST_FAIL == "add" && s == 0 && specs !== SO_RESTORING) throw new Error("test: add failed");
        if (typeof SO_TEST_FAIL != "undefined" && SO_TEST_FAIL == "addall") throw new Error("test: add failed");
        style[prop].add(specs[s]);
    }
}
var SO_RESTORING = null;

function soCopyCollection(style, prop) {
    var fields = SO_COLLECTION_FIELDS[prop];
    // Read everything first. While the child inherits, its collection shows the
    // parent's items, so removing first would leave nothing to copy. A field that
    // cannot be read stops the reset before anything is removed.
    var theirs = soReadItems(style.basedOn[prop], fields);
    var mine = soReadItems(style[prop], fields);
    try {
        soReplaceItems(style, prop, theirs);
    } catch (e) {
        // Try to put the child's own items back, and say whether that worked.
        try { SO_RESTORING = mine; soReplaceItems(style, prop, mine); }
        catch (e2) { throw new Error("copying failed (" + e + ") and putting the style's own items back also failed (" + e2 + ")"); }
        finally { SO_RESTORING = null; }
        throw new Error("copying failed (" + e + "); the style's own items were put back");
    }
}

// A value as text, for comparing a setting before and after.
// A font is compared by family only: its name also carries the font style, which
// is a separate setting (resetting Font Style changes the font's name).
function soValKey(v) {
    try { if (v instanceof Font) return "F:" + v.fontFamily; } catch (e0) {}
    try { if (v && v.name !== undefined) return "N:" + v.name; } catch (e) {}
    return "S:" + String(v);
}

// Read the style's list and require a real result (not a message).
function soMustList(doc, style, xml) {
    var r = listOverrides(doc, style, xml);
    if (typeof r == "string") throw new Error(r);
    return r;
}

// Reset the given rows to the Based On style, in one Undo step.
// before = the full list for this style (from listOverrides); read here when not given.
//
// While resetting, InDesign can clear a setting that was not selected (Font Style
// when Font Family is reset). Each unselected single-value setting is saved first
// and compared by value afterwards; one that changed is set back. The IDML is read
// once more after the Undo step to check the result.
//
// Returns {errors, snapshotErrors, restored, lost, stillHeld, unverified, xml}.
// unverified is a message when that last read failed: the reset was applied but not checked.
function resetOverrides(style, rows, doc, before) {
    doc = doc || soDocOf(style);
    before = before || soMustList(doc, style);   // throws before anything is changed
    var res = {errors: [], snapshotErrors: [], restored: [], lost: [], stillHeld: [], unverified: null, xml: null};
    var picked = {};
    for (var i = 0; i < rows.length; i++) picked[rows[i].key] = true;
    var keep = [];
    function run() {
        for (var b = 0; b < before.length; b++) {
            var row = before[b];
            if (picked[row.key] || !row.canReset || SO_COLLECTIONS[row.key]) continue;
            try { var v = style[row.prop]; keep.push({row: row, value: v, key: soValKey(v)}); }
            catch (e0) { res.snapshotErrors.push(row.label + ": " + e0); }
        }
        for (var j = 0; j < rows.length; j++) {
            var r = rows[j];
            if (!r.canReset) { res.errors.push(r.label + ": cannot be reset by this script (use Style Options)"); continue; }
            try {
                if (SO_COLLECTIONS[r.key]) soCopyCollection(style, r.prop);
                else style[r.prop] = style.basedOn[r.prop];
            } catch (e) {
                res.errors.push(r.label + ": " + (e.message || e));
            }
        }
        for (var k = 0; k < keep.length; k++) {
            var kp = keep[k], now;
            try { now = soValKey(style[kp.row.prop]); } catch (e1) { res.lost.push(kp.row.label + " (could not be read: " + e1 + ")"); kp.done = true; continue; }
            if (now == kp.key) continue;
            try { style[kp.row.prop] = kp.value; } catch (e2) { res.lost.push(kp.row.label + " (" + e2 + ")"); kp.done = true; continue; }
            kp.setBack = true;
        }
        // Setting something back must not undo a selected reset.
        for (var m = 0; m < rows.length; m++) {
            var pr = rows[m];
            if (!pr.canReset || SO_COLLECTIONS[pr.key]) continue;
            try {
                if (soValKey(style[pr.prop]) != soValKey(style.basedOn[pr.prop])) res.errors.push(pr.label + ": does not match the Based On style after the reset");
            } catch (e5) { res.errors.push(pr.label + ": could not be checked (" + e5 + ")"); }
        }
    }
    app.doScript(run, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Reset style settings");

    // Check the result: read the IDML again (outside the Undo step; reading changes nothing).
    var after;
    try {
        if (typeof SO_TEST_FAIL != "undefined" && SO_TEST_FAIL == "verify") throw new Error("test: verify read failed");
        res.xml = soReadStylesXml(doc);
        after = soMustList(doc, style, res.xml);
    } catch (e3) {
        res.unverified = String(e3.message || e3);
        for (var u = 0; u < keep.length; u++) if (keep[u].setBack) res.restored.push(keep[u].row.label + " (not checked)");
        return res;
    }
    var held = {};
    for (var a = 0; a < after.length; a++) held[after[a].key] = after[a];
    for (var p = 0; p < rows.length; p++) if (held[rows[p].key]) res.stillHeld.push(rows[p].label);
    for (var q = 0; q < keep.length; q++) {
        var kq = keep[q];
        if (kq.done) continue;
        var valueOk = false;
        try { valueOk = soValKey(style[kq.row.prop]) == kq.key; } catch (e4) {}
        if (valueOk && held[kq.row.key]) { if (kq.setBack) res.restored.push(kq.row.label); }
        else res.lost.push(kq.row.label + (valueOk ? " (now taken from the Based On style)" : " (value changed)"));
    }
    return res;
}

// ---------- dialog ----------

function soStyleList(doc) {
    var out = [];
    var ps = doc.allParagraphStyles, cs = doc.allCharacterStyles;
    for (var i = 0; i < ps.length; i++) if (!soIsRootStyle(ps[i])) out.push(ps[i]);
    for (var j = 0; j < cs.length; j++) if (!soIsRootStyle(cs[j])) out.push(cs[j]);
    return out;
}

function soLabel(style) {
    var path = style.name;
    var p = style.parent;
    while (p instanceof ParagraphStyleGroup || p instanceof CharacterStyleGroup) { path = p.name + " > " + path; p = p.parent; }
    return (soKind(style) == "Paragraph" ? "Paragraph: " : "Character: ") + path;
}

function soSelectedStyle() {
    if (!app.selection.length) return null;
    try { return app.selection[0].appliedParagraphStyle || null; } catch (e) { return null; }
}

function soNote(row) {
    var n = [];
    if (row.sameAsParent) n.push("same value");
    if (!row.canReset) n.push("Style Options only");
    return n.join("; ");
}

function soMain() {
    if (!app.documents.length) { alert("Open a document first."); return; }
    var doc = app.activeDocument;
    var styles = soStyleList(doc);
    if (!styles.length) { alert("No style in this document is based on another style."); return; }
    var xml;
    try { xml = soReadStylesXml(doc); }
    catch (e) { alert("Could not read the styles (the document could not be exported to IDML).\n" + e); soCleanupNote(); return; }

    var w = new Window("dialog", "Style overrides");
    w.alignChildren = "fill";
    var top = w.add("group");
    top.add("statictext", undefined, "Style:");
    var dd = top.add("dropdownlist");
    for (var i = 0; i < styles.length; i++) dd.add("item", soLabel(styles[i]));
    var lb = w.add("listbox", undefined, "", {multiselect: true, numberOfColumns: 4, showHeaders: true,
        columnTitles: ["Setting", "This style", "Based On", "Note"], columnWidths: [200, 150, 150, 160]});
    lb.preferredSize = [680, 300];
    var note = w.add("statictext", undefined, "", {multiline: true});
    note.preferredSize = [680, 34];
    var btns = w.add("group");
    btns.alignment = "right";
    var resetBtn = btns.add("button", undefined, "Reset Selected");
    btns.add("button", undefined, "Close", {name: "cancel"});

    var rows = [];
    function load() {
        lb.removeAll();
        var style = styles[dd.selection.index];
        var r = listOverrides(doc, style, xml);
        if (typeof r == "string") { rows = []; note.text = r; resetBtn.enabled = false; return; }
        rows = r;
        var hidden = 0;
        for (var k = 0; k < rows.length; k++) {
            var it = lb.add("item", rows[k].label);
            it.subItems[0].text = rows[k].value;
            it.subItems[1].text = rows[k].parentValue;
            it.subItems[2].text = soNote(rows[k]);
            if (rows[k].sameAsParent) hidden++;
        }
        note.text = rows.length ?
            rows.length + " setting(s) held by this style. " + (hidden ? hidden + " match the Based On value now but will not follow it if it changes. " : "") +
            "Sizes are in points." :
            "No settings are listed for this style.";
        resetBtn.enabled = rows.length > 0;
    }
    var start = -1, sel = soSelectedStyle();
    if (sel) for (var s = 0; s < styles.length; s++) if (styles[s] == sel) { start = s; break; }
    dd.selection = start < 0 ? 0 : start;
    load();
    // The selected paragraph's style is not in the list (for example Body, based on [No Paragraph Style]).
    if (sel && start < 0) {
        var selName = "";
        try { selName = sel.name; } catch (e3) {}
        note.text = "The selected paragraph's style \"" + selName + "\" is not based on another style, so it is not listed.\n" + note.text;
    }
    dd.onChange = load;
    resetBtn.onClick = function () {
        var picked = [];
        for (var i = 0; i < lb.items.length; i++) if (lb.items[i].selected) picked.push(rows[i]);
        if (!picked.length) { alert("Select one or more settings in the list."); return; }
        var style = styles[dd.selection.index];
        var res;
        try { res = resetOverrides(style, picked, doc, rows); }
        catch (e) {
            alert("The reset stopped: " + e + "\nClose this dialog and use Edit > Undo if anything changed.");
            w.close(); return;
        }
        var msg, undo = false;
        if (res.unverified) {
            msg = "The reset was applied, but the styles could not be read again to check it:\n" + res.unverified;
            undo = true;
        } else {
            xml = res.xml;
            load();
            msg = "Reset " + (picked.length - res.stillHeld.length) + " of " + picked.length + ".";
            if (res.stillHeld.length) { msg += "\nStill held by this style: " + res.stillHeld.join(", "); undo = true; }
        }
        if (res.restored.length) msg += "\nInDesign also changed " + res.restored.join(", ") + "; set back to the old value.";
        if (res.lost.length) { msg += "\nNot kept as before: " + res.lost.join(", "); undo = true; }
        if (res.snapshotErrors.length) { msg += "\nCould not be saved before the reset, so not checked: " + res.snapshotErrors.join(", "); undo = true; }
        if (res.errors.length) { msg += "\n" + res.errors.join("\n"); undo = true; }
        if (undo) msg += "\nTo reverse the whole reset, close this dialog and use Edit > Undo.";
        alert(msg);
        if (res.unverified) w.close();
    };
    try { w.show(); } finally { soCleanupNote(); }
}

function soCleanupNote() {
    if (!SO_CLEANUP_ERRORS.length) return;
    alert("Some temporary files could not be removed:\n" + SO_CLEANUP_ERRORS.join("\n"));
    SO_CLEANUP_ERRORS = [];
}

if (typeof STYLE_OVERRIDES_TEST == "undefined") soMain();

If you are cleaning up an old template, Why InDesign Asks for a Replacement When You Delete an Unused Paragraph Style has a script that lists which styles are based on a style before you delete it.

What I tested

I tested in InDesign 21.6 on Windows. The cases below were run by a test script that builds its own small documents and calls the script's functions without the dialog. I also checked the dialog from the Scripts panel on a document I built by hand, with the Caption and Body styles described above.

Case Result
Child sets Font Style and Size Both listed, with the parent's Size
Parent changed to the child's Space Before Listed as "same value"
Reset Font Style only Font Style follows the parent; Size stays
Reset the "same value" Space Before, then change the parent Child follows
Alignment, Rule Above, list type, hyphenation All reset
Child has its own tab, parent has another Listed; after reset the child follows new parent tabs
Child removed the parent's tab Listed as 0 items against 1
Child has its own nested style, parent has another Listed; after reset the child follows
Child adds a GREP style to the parent's Listed; after reset the child follows
Child removed the parent's GREP style Listed as 0 items; after reset the child follows
Style in a nested style group, name with a colon and quotes, another style with the same name outside the group The right style is read
Character style Listed and reset the same way
Font Family set in the child Shows Myriad Pro against Minion Pro; reset
Undo after resetting two settings One Undo brings both back
[Basic Paragraph], [No Paragraph Style], [None] Not listed
Three levels: setting comes from the grandparent The grandparent's value is shown
A style that sets nothing Empty list; temporary files removed
Parent's tabs, nested and GREP styles after resetting the child Every item unchanged
Child has its own nested line styles Listed; after reset the child follows
Child's GREP style differs from the parent's only by one space Not marked "same value"
Bullet character set in the child Listed as "Style Options only"; not changed
A setting with an unusual internal name (OpenType HV Kana) Listed and reset
Reset Font Family when the child also sets Font Style Font Style kept; a later change to the parent's family carries over
Same, but the child's Font Style matched the parent Font Style is lost and reported
Reset Font Style only Font Family stays as the child set it
Copying a GREP list fails (forced in the test) The child's own items are back; parent unchanged
Copying fails and putting the items back fails too (forced) Both failures reported; one Undo restores the list
The IDML export fails (forced in the test) Error returned; nothing changed; temporary files removed
The check after a reset fails (forced in the test) Reported as applied but not checked; earlier errors kept
Undo after resetting a GREP list and a size One Undo brings both back

I did not test macOS, other InDesign versions, books, object, table or cell styles, numbering restart settings, or very large documents. I also did not check, in the dialog, whether typing the same value again into a setting that already matches the parent removes it. The script's reset does remove it.

Share: X Email