Skip to main content
Known Participant
September 11, 2017
Answered

Change all text color in text box

  • September 11, 2017
  • 1 reply
  • 5204 views

Hi guys and greetings from Norway!

I've got something that is almost working. I want to change the text color in a selected box from e.g. black to white.

Previously I have this script from another post at this site. However, it's a problem. It only changes the first paragraph. How do I make it cycle through all the text?

Pseudo-code could be either something that selects all text and then changes color of it, or something that counts the paragraphs and then cycle through them one by one. Any ideas on how to solve this?

Code:

var i, p, color; 

for (i=0; i<app.selection[0].paragraphs.length; i++) { 

    p = app.selection[0].lines

    color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]); 

        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; 

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

It does not need to iterate.

If selection is text or textFrame use

var color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]);

app.selection[0].texts.everyItem().fillColor = color;

//function makeColor (...) {...}

Jarek

1 reply

Jump_Over
Jump_OverCorrect answer
Legend
September 11, 2017

Hi,

It does not need to iterate.

If selection is text or textFrame use

var color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]);

app.selection[0].texts.everyItem().fillColor = color;

//function makeColor (...) {...}

Jarek

Maggern78Author
Known Participant
September 11, 2017

Thank you very much, that worked!

I slimmed it down to NOT make a new swatch.

Black:

app.selection[0].texts.everyItem().fillColor = "Black";

Or for white:

app.selection[0].texts.everyItem().fillColor = "Paper";