Skip to main content
SuzzyFlamingo
Inspiring
July 24, 2025
Question

KeyBoard SC for applying styles

  • July 24, 2025
  • 3 replies
  • 157 views

Hi, Dear Friends!

I want to apply a paragraph style and clear all character formatting using a single keyboard shortcut. ChatGPT said it could not be done and suggested run a script to clear (and attach that to a SC) and then apply the style. but it is not working good

Thank you, and have a good day!
Susan Flamingo

3 replies

Joel Cherney
Community Expert
Community Expert
July 24, 2025

This script applies a paragraph style called "Body Text" and then immediately clears all paragraph overrides. You can edit the style name on line 66, to customize this script for your preferred paragraph style. This script also clears paragraph-level formatting only; if you want it to clear character-level formatting as well, you can uncomment line 49. 

 

// Apply Paragraph Style and Clear Overrides


#target indesign

function applyStyleAndClearOverrides(styleName) {
    // Check if InDesign is running and a document is open
    if (app.documents.length === 0) {
        alert("Please open a document first.");
        return;
    }
    
    var doc = app.activeDocument;
    
    // Check if there's a text selection
    if (app.selection.length === 0) {
        alert("Please select some text first.");
        return;
    }
  
    // Find the paragraph style
    var paragraphStyle = null;
    try {
        paragraphStyle = doc.paragraphStyles.itemByName(styleName);
        if (!paragraphStyle.isValid) {
            alert("Paragraph style '" + styleName + "' not found in this document.");
            return;
        }
    } catch (e) {
        alert("Error finding paragraph style: " + e.message);
        return;
    }
    
    // Apply the style to selected text
    try {
        for (var i = 0; i < app.selection.length; i++) {
            var selection = app.selection[i];
            
            // Check if this selection item has text content
            if (selection.hasOwnProperty("parentStory")) {
                // Apply paragraph style
                selection.appliedParagraphStyle = paragraphStyle;
                
                // Clear paragraph overrides
                selection.clearOverrides(OverrideType.PARAGRAPH_ONLY);
                
                // Optionally clear character overrides as well
                // Uncomment the next line if you want to clear character overrides too
                // selection.clearOverrides(OverrideType.CHARACTER_ONLY);
            }
        }
        
        // Success message
        alert("Paragraph style '" + styleName + "' applied and overrides cleared successfully!");
        
    } catch (e) {
        alert("Error applying style: " + e.message);
    }
}

// Main execution
function main() {
    // Specify the paragraph style name here
    var styleName = "Body Text"; // Change this to your desired paragraph style name
    applyStyleAndClearOverrides(styleName);
}

// Run the script
main();

 

 

 

Mike Witherell
Community Expert
Community Expert
July 24, 2025

Something I often forget about: You can select many or all paragraphs in a story thread, and find the "Clear Overrides" button at the bottom of the Paragraph Styles panel. 

Mike Witherell
BobLevine
Community Expert
Community Expert
July 24, 2025

A script is not needed. Select the paragraph, right click the style in the paragraph styles panel and choose Apply "style name", Clear Overrides.

I'm not sure how much fast a script is going to be.