Skip to main content
dublove
Legend
August 1, 2026
Answered

Is there a script that can load all styles with just one click?

  • August 1, 2026
  • 4 replies
  • 42 views

I have been trying to generate styles using scripts for a long time.
Suddenly realizing that this is a thankless task.
Perhaps importing styles can be easily implemented.

 

If my script is located at: ../scripts/myScript/aa.jsx
My style file can be found at: ./scripts/styles/myStyle.indd
Is there a script that can import all style structures (including group names) with one click?
One click import of all, no need to select.

    Correct answer dublove

    I found the problem, the path definition part cannot be included in the function. It should be placed outside.
    I don't know the principle.

        //Warning: Be careful of extra spaces in the path
    var myScript = app.activeScript;
    var styPath = String(myScript.parent.parent + '/StylesLib/样式模板/001-base style.indt');
    app.doScript(allStyImport, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'allStyImport')

    //allStyImport();
    function allStyImport() {
    app.activeDocument.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    app.activeDocument.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    app.activeDocument.importStyles(ImportFormat.CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    app.activeDocument.importStyles(ImportFormat.TABLE_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    app.activeDocument.importStyles(ImportFormat.TABLE_AND_CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    app.activeDocument.importStyles(ImportFormat.OBJECT_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    }

     

    4 replies

    dublove
    dubloveAuthor
    Legend
    August 1, 2026

    I found this by @winterm
    How to modify it to the relative path from my previous location

    var styPath = 'C:/0000/image to Frame.indt';
    app.activeDocument.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.TABLE_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.TABLE_AND_CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.OBJECT_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    alert("All Styles from Master loaded");

     

    dublove
    dubloveAuthor
    Legend
    August 2, 2026

    Why is it wrong for me to change the path to a relative path?

    I guess File (styPath) cannot accept it.
    Which command can be accepted?

    var myScript = app.activeScript;
    var styPathA = String(myScript.parent.parent + '/StylesLib/styles/001-base style.indt');
    var styPath = decodeURIComponent(styPathA);
    alert(styPath);

     

    dublove
    dubloveAuthor
    Legend
    August 2, 2026

    It seems that I made a mistake, there is a small space that should not belong to the path.

    It's alright now.
    But I use:

    app.doScript(allStyImport, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'allStyImport')
    It will prompt the following error.

    It will prompt the following error. ​@m1b 
    But there is no problem calling allStyImport() directly.

     

    Complete code:


    app.doScript(allStyImport, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'allStyImport')

    //allStyImport();
    function allStyImport() {
    //Warning: Be careful of extra spaces in the path
    var myScript = app.activeScript;
    var styPath = String(myScript.parent.parent + '/StylesLib/样式模板/001-base style.indt');

    app.activeDocument.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.TABLE_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.TABLE_AND_CELL_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);

    app.activeDocument.importStyles(ImportFormat.OBJECT_STYLES_FORMAT, File(styPath), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    }