Skip to main content
IgnorantTurtle
Known Participant
July 22, 2011
Answered

Looking for a automated way to alternate text color in a list

  • July 22, 2011
  • 2 replies
  • 3448 views

I have a long list of names and I'm looking for an automated way to color them.

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

Got close with converting the text into a table, but I can only get cell fills or cell strokes to alternate.

I couldn't figure out a way to control the text stroke and fill.

Grep? Tables? External script?

Any and all answers are greatly appreciated,

Thanks again

This topic has been closed for replies.
Correct answer ja3754

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

I'm not sure I understand the sequence of colours as you've described it, but if you just want to cycle between three colours, such as:

100k

50k

30k

100k

50k

30k

100k

etc.

then you could set up a paragraph style for each colour.  After all three styles are created, go back to edit each style and change the "Next Style" (in the General tab) to the next style in the sequence.

To apply to the text: select all the text then right click on the 100k style in the Paragraph Styles pallet and choose "Apply "100k" then Next Style".

2 replies

ja3754Correct answer
Participating Frequently
July 24, 2011

for example: Every other name becomes 50% K and every third name becomes 30% K (?)

I'm not sure I understand the sequence of colours as you've described it, but if you just want to cycle between three colours, such as:

100k

50k

30k

100k

50k

30k

100k

etc.

then you could set up a paragraph style for each colour.  After all three styles are created, go back to edit each style and change the "Next Style" (in the General tab) to the next style in the sequence.

To apply to the text: select all the text then right click on the 100k style in the Paragraph Styles pallet and choose "Apply "100k" then Next Style".

John Hawkinson
Inspiring
July 24, 2011

Oh, yes, that way works too. Sometimes it's easy to put on one's scripting blinders when the question gets asked in the scripting forum.

Of course, if you truly want every-other and every-third, then you need six styles with Next Styles, which can get a little tricksy.

John Hawkinson
Inspiring
July 23, 2011

A short easy script:

var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
  p = app.selection[0].paragraphs;
  if (i%3 === 2) { p.fillTint = 50; }
  if (i%2 === 1) { p.fillTint = 30; }
}

Though what's supposed to happen every six, when the 2nd and the 3rd line up, I'm not sure.

This assumes one paragraph per line. I suppose you could replace .paragraphs with .lines if you wanted.

Oh, this operates on the selected textframe. So select a text frame first. (Well, or anything with paragraphs/lines I guess).

IgnorantTurtle
Known Participant
July 23, 2011

Thanks John !

-Stupid Question:  where do I paste the script ?

I mean is there a place in indesign for code ? or is this an external script ?

I'm on a a mac, if that matters.

-If I wanted just every second line to tint, I'm assuming it would be

var i, p;
for (i=0; i<app.selection[0].paragraphs.length; i++) {
  p = app.selection[0].lines;
  if (i%3 === 2) { p.fillTint = 50; }
 
}
Thanks again for your help.
John Hawkinson
Inspiring
July 23, 2011

Save it as alternateText.jsx (or whatever you like) in your favorite text editor (e.g. TextEdit) and then follow the instructions at http://www.danrodney.com/scripts/directions-installingscripts.html.

-If I wanted just every second line to tint, I'm assuming it would be

Not quite, that would do every 3rd line:

  if (i%3 === 2) { p.fillTint = 50; } }

"i%3" is an expressioin that returns the remainder of i divided by 3. i is the line count. So for the first line, i is 0 and i%3 is 0. Second line i is 1 and i%3 is 1. Third line: i is 2 and i%3 is 2. Fouth line: i is 3 and i%3 is 0. Fifth line: i is 4 and i%3 is 1. etc. etc.

So for every second line, use i%2. You can say "i%2===1" if you want every other line starting with the 2nd line. Or "i%2===0" if you want every other line starting with the first line.