Skip to main content
mirza5313
Known Participant
February 6, 2017
Answered

Text Layers color change Action

  • February 6, 2017
  • 3 replies
  • 6181 views

I need a Photoshop action/script for a file which contains around 50 text layers. I need the action/script to alter the colour of each text layer and apply new colours to each one individually. Each time I run the action, the script should randomise the colours again.

The new colours will be preset from a group of colours e.g.

"Colour group one": #000000, #f3f3f3, #76f8f7, #333333, #454566, #d87d56

"Colour group two": #111111, #c7c8c7, #f9h9d9, #999999, #d3d2d2, #a8aha8

Etc....

Example:

I have a file containing 50 text layers. I want to change all of the text layers to the "Colour Group One" colours. I run the script/action and each text layer will have one of the colours from "Colour Group One". Each time I run the action, each text layer will change colours again.

I hope this is clear but understand that it might not be! (I have add an example image to text color change.)

Thanks in advance!

This topic has been closed for replies.
Correct answer Tomas Sinkunas

There you go buddy.

 

PSD Script: Set Random text color from given array

 

Simply add hex colours to colorArray variable and you should be golden

 

// Script applies random color from given color array
// to all text layers in the document.
//
// by Tomas Sinkunas www.rendertom.com

(function(){
	#target photoshop

	// Define HEX colors separated by comma
	var colorArray = ["#000000", "#f3f3f3", "#76f8f7", "#333333", "#454566", "#d87d56"];

	// Collect all text layers in the document
	var textLayers = getTextLayers(app.activeDocument);

	// Loop through all text layers in the document
	for (var t = 0, tl = textLayers.length; t < tl ; t ++) {
		// Get random color from color array
		var randomColor = colorArray[Math.floor(Math.random() * colorArray.length)];
		// Remove pound sing from the color value
		if (randomColor.charAt(0) === "#")
			randomColor = randomColor.substr(1);

		// Initiate new color
		var textColor = new SolidColor;
			textColor.rgb.hexValue = randomColor;

		// Set text Layer Color
		textLayers[t].textItem.color = textColor;
	}

	function getTextLayers (doc, layers) {
		layers = layers || [];
		for (var i = 0, il = doc.layers.length; i < il; i ++) {
			if (doc.layers[i].typename == "LayerSet") {
				getTextLayers(doc.layers[i], layers)
			} else {
				if (doc.layers[i].kind == "LayerKind.TEXT") {
					layers.push(doc.layers[i])
				}
			}
		}
		return layers
	}
})();

 

3 replies

Participant
September 25, 2020

Heey Can this script pick colors from pictures instead of adding the hex manually ? If there any script that could take colors from the picture in the design and put it on text ?

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
February 6, 2017

There you go buddy.

 

PSD Script: Set Random text color from given array

 

Simply add hex colours to colorArray variable and you should be golden

 

// Script applies random color from given color array
// to all text layers in the document.
//
// by Tomas Sinkunas www.rendertom.com

(function(){
	#target photoshop

	// Define HEX colors separated by comma
	var colorArray = ["#000000", "#f3f3f3", "#76f8f7", "#333333", "#454566", "#d87d56"];

	// Collect all text layers in the document
	var textLayers = getTextLayers(app.activeDocument);

	// Loop through all text layers in the document
	for (var t = 0, tl = textLayers.length; t < tl ; t ++) {
		// Get random color from color array
		var randomColor = colorArray[Math.floor(Math.random() * colorArray.length)];
		// Remove pound sing from the color value
		if (randomColor.charAt(0) === "#")
			randomColor = randomColor.substr(1);

		// Initiate new color
		var textColor = new SolidColor;
			textColor.rgb.hexValue = randomColor;

		// Set text Layer Color
		textLayers[t].textItem.color = textColor;
	}

	function getTextLayers (doc, layers) {
		layers = layers || [];
		for (var i = 0, il = doc.layers.length; i < il; i ++) {
			if (doc.layers[i].typename == "LayerSet") {
				getTextLayers(doc.layers[i], layers)
			} else {
				if (doc.layers[i].kind == "LayerKind.TEXT") {
					layers.push(doc.layers[i])
				}
			}
		}
		return layers
	}
})();

 

mirza5313
mirza5313Author
Known Participant
February 7, 2017

Thanks Tomas Sinkunas for your prompt reply and script... This is amazing script just what i wanted.....

Thanks a lot!!!

pixxxelschubser
Community Expert
Community Expert
February 6, 2017

Hi mirza5313​,

Do you search for help to writing a script?

Or do you search for someone who is writing the script for you?

In both cases: please upload an example file for testing.