InDesign script to alternate text color every other line in a text box
InDesign script to alternate text color every other line in a text box
Question
I have a very long list of names that I need to alternate the CMYK color value every other line.
I found this script online that changes the tint every 3rd line:
var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
p = app.selection[0].lines[i];
if (i%3 === 2) { p.fillTint = 50; }
}
I tried changing the script to change the CMYK value doing this:
var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
p = app.selection[0].lines[i];
if (i%2 === 1) { p.colorValue=[0,100,100,0]; }
}
But using "colorValue" is not supported. How can I change the script to make every other line in a text box change the color value?
2015/10/26
Popular Answer
Credit to Kasyan Servetsky for creating the script.
var i, p, color;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
p = app.selection[0].lines[i];
color = makeColor("C=0 M=100 Y=100 K=0", ColorSpace.CMYK, ColorModel.process, [0, 100, 100, 0]);
if (i%2 === 1) {
p.fillColor = color;
}
}
function makeColor(colorName, colorSpace, colorModel, colorValue) {
var doc = app.activeDocument;
var color = doc.colors.item(colorName);
if (!color.isValid) {
color = doc.colors.add({name: colorName, space: colorSpace, model: colorModel, colorValue: colorValue});
}
return color;
}
2015/10/26