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

InDesign Javascript Paragraph Shading question

Explorer ,
Nov 27, 2025 Nov 27, 2025

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.

TOPICS
Scripting
195
Translate
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 2 Correct answers

Community Expert , Nov 27, 2025 Nov 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]}
...
Translate
Engaged , Nov 27, 2025 Nov 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
}
Translate
Community Expert ,
Nov 27, 2025 Nov 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});
    }
}
Translate
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
Explorer ,
Nov 27, 2025 Nov 27, 2025

Great! Thanks for the help Rob, much appreciated 🙂

Translate
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
Engaged ,
Nov 27, 2025 Nov 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
}
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
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
Explorer ,
Nov 27, 2025 Nov 27, 2025
LATEST

Great! Thanks for the help Prabu, much appreciated 🙂

Translate
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