Okay, got it. I think the following script may do what you want, but it also clears all character level overrides in the selected text or text frames. See if it does what you need.
- Mark
/**
* Attempts to reproduce the function of the menu action
* `Apply "^1" then Next Style, Clear Character Styles`
* on the select text or text frame.
* Known limitations: this script, unlike the above function,
* also removes *any* character-level overrides from the text.
* @discussion https://community.adobe.com/t5/indesign-discussions/please-help-me-write-a-script-for-the-following-command/m-p/13883054
*/
function main() {
var doc = app.activeDocument,
items = doc.selection;
for (var i = 0; i < items.length; i++)
clearCharacterOverrides(doc, items[i], false);
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Clear Character Overrides');
/**
* Clears character overrides
* retaining paragraph style.
* @7111211 m1b
* @version 2023-06-22
* @9397041 {Document} doc - an Indesign document.
* @9397041 {Text|TextFrame} text - any Indesign object with texts.
*/
function clearCharacterOverrides(doc, text) {
if (!text.hasOwnProperty('texts'))
return;
text = text.texts[0];
if (!text.isValid)
return;
// apply [None]
text.paragraphs.everyItem().applyCharacterStyle(doc.characterStyles[0]);
text.clearOverrides(OverrideType.ALL);
};