Skip to main content
Known Participant
November 27, 2025
Answered

InDesign Javascript Paragraph Shading question

  • November 27, 2025
  • 2 replies
  • 245 views

Hi There,

Please can someone help with a question about setting the Paragraph Shading colour within a Paragraph Style.

I've tried a few things but as yet haven't managed to nail it.

Here's the snippet I've been testing...

allPars = app.activeDocument.allParagraphStyles;
	for (var g = 1; g < allPars.length; g++) {
		allPars[g].paragraphShadingColor.name = "This Colour";
		allPars[g].paragraphShadingColor.name = allPars.itemByName("This Colour");
	}

 Neither of the two versions, shown above, work?
Is this not possible via a script?

Thanks.

Correct answer Anantha Prabu G

Try this:

 

var doc = app.activeDocument;
var allPars = doc.allParagraphStyles;
var sw = doc.swatches.itemByName("This Colour");

for (var g = 1; g < allPars.length; g++) {
var s = allPars[g];
s.paragraphShadingOn = true;
s.paragraphShadingColor = sw;
//s.paragraphShadingTint = 100; // optional
}

2 replies

Anantha Prabu G
Anantha Prabu GCorrect answer
Legend
November 27, 2025

Try this:

 

var doc = app.activeDocument;
var allPars = doc.allParagraphStyles;
var sw = doc.swatches.itemByName("This Colour");

for (var g = 1; g < allPars.length; g++) {
var s = allPars[g];
s.paragraphShadingOn = true;
s.paragraphShadingColor = sw;
//s.paragraphShadingTint = 100; // optional
}
Design smarter, faster, and bolder with InDesign scripting.
Known Participant
November 27, 2025

Great! Thanks for the help Prabu, much appreciated 🙂

rob day
Community Expert
Community Expert
November 27, 2025

Hi @Nick37129562ryen , You don’t need .name—this assumes a Swatch named "This Color" exists"

 

var d = app.activeDocument
var allPars = d.allParagraphStyles;

for (var g = 1; g < allPars.length; g++) {
		allPars[g].paragraphShadingColor = "This Color";
}

 

If you are not sure "This Color" exists then:

 

 
var d = app.activeDocument
var allPars = d.allParagraphStyles;
var sc = makeSwatch(d, "This Color")
//set the color’s properties
sc.properties = {space:ColorSpace.CMYK, colorValue:[0,50,0,0]}

for (var g = 1; g < allPars.length; g++) {
		allPars[g].paragraphShadingColor = "This Color";
}

/**
* Makes a new named Swatch 
* @ param the document to add the color to 
* @ param color name 
* @ return the new swatch 
*/

function makeSwatch(d, n){
    if (d.colors.itemByName(n).isValid) {
        return d.colors.itemByName(n);
    } else {
        return d.colors.add({name:n});
    }
}
Known Participant
November 27, 2025

Great! Thanks for the help Rob, much appreciated 🙂