Copy link to clipboard
Copied
Good idea!
Can someone please help me write a script for the following command: apply "name of paragraph style", clear character style. so i can make for this script a shortcut.
Thank you!
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.
...
Copy link to clipboard
Copied
So when you run the script it shows you a menu of all the paragraph styles to choose from?
- Mark
Copy link to clipboard
Copied
no, it should just execute the command in blue, on my text selected.
My selected text already has a paragraph style, but also has a character style which conflicts with the paragraph style and I want to clear it, the only way is to open each time the paragraph style menu, right click on the style and press on the command. and I want a script to do that and then i'll add a key shortcut to that script.
Thank You!
Copy link to clipboard
Copied
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.
* @author m1b
* @version 2023-06-22
* @Param {Document} doc - an Indesign document.
* @Param {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);
};
Copy link to clipboard
Copied
Thank You! I tried it out and indesign opened an error window, atached below.
Copy link to clipboard
Copied
Sorry, i didn't copy it correctly, it actually works! amazing!
Thank You!
Copy link to clipboard
Copied
Great to hear! Yes it must be a plain text file, not rich text.
- Mark