• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

please help me write a script for the following command

Community Beginner ,
Jun 21, 2023 Jun 21, 2023

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.

YY30595644t3av_0-1687383059301.png

 

Thank you!

TOPICS
Scripting

Views

221

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 21, 2023 Jun 21, 2023

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.
...

Votes

Translate

Translate
Community Expert ,
Jun 21, 2023 Jun 21, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 21, 2023 Jun 21, 2023

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2023 Jun 21, 2023

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);

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

Thank You!  I tried it out and indesign opened an error window, atached below.

YY30595644t3av_0-1687391627543.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

Sorry, i didn't copy it correctly, it actually works! amazing!

 

Thank You!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

LATEST

Great to hear! Yes it must be a plain text file, not rich text.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines