Skip to main content
Participant
March 30, 2015
Answered

script random colours on letters

  • March 30, 2015
  • 3 replies
  • 1242 views

Hey, I would like to select a text frame and use a script so that each letter gets randomly coloured with one of the swatches out of my panel.

I’ve seen there are scripts to colourise shapes, but it's important that it stays as a font. I don’t want to outline the font.

Does a script like this exist?

Thanks for any tips

This topic has been closed for replies.
Correct answer Vamitul

here you go:

(function(){

  var tf=app.activeDocument.selection[0];

  var chars=tf.characters.everyItem().getElements();

  var col=app.activeDocument.swatches.length-1;

  for (var i=0; i<chars.length; i++){

  var rand=Math.floor((Math.random() * col) + 1);

  chars.fillColor=app.activeDocument.swatches[rand];

  }

}());

3 replies

InazaziAuthor
Participant
March 30, 2015

One more question. To avoid the black, white and non colour [which can't be deleted] - is it possible that the script only use colours out of a group?

Cheers

brian_p_dts
Community Expert
Community Expert
April 19, 2024

Resurrecting a very old thread to say: 

 

chars is missing its iterator in the last line due to forum migration. It should begin chars[i] for anyone stumbling across it now. 

 

InazaziAuthor
Participant
March 30, 2015

Awesome, thank you.

Vamitul
VamitulCorrect answer
Legend
March 30, 2015

here you go:

(function(){

  var tf=app.activeDocument.selection[0];

  var chars=tf.characters.everyItem().getElements();

  var col=app.activeDocument.swatches.length-1;

  for (var i=0; i<chars.length; i++){

  var rand=Math.floor((Math.random() * col) + 1);

  chars.fillColor=app.activeDocument.swatches[rand];

  }

}());