Copy link to clipboard
Copied
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;
}
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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";
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more