Skip to content

Instantly share code, notes, and snippets.

@theinsanecow
Created March 31, 2011 04:23
Show Gist options
  • Save theinsanecow/895810 to your computer and use it in GitHub Desktop.
Save theinsanecow/895810 to your computer and use it in GitHub Desktop.
Photoshop script to update the colour of all shape and fill layers that are the same colour as the currently selected layer. Uses the foreground colour as the new colour. Tested in CS4
// ChangeColor.jsx
//
// This photoshop script finds all shape and solid fill layers that match the color
// of the currently selected shape/fill layer and changes their color to the
// foreground color.
//
// Tested on Adobe Photoshop CS4 (Mac)
// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop
// in case we double clicked the file
app.bringToFront();
var sColor = getFillColor();
for( var i = 0; i < app.activeDocument.layers.length; i++ )
{
app.activeDocument.activeLayer = app.activeDocument.layers[i];
if( getFillColor().rgb.hexValue == sColor.rgb.hexValue )
setColorOfFillLayer( app.foregroundColor );
}
function setColorOfFillLayer( sColor ) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID('contentLayer'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
var fillDesc = new ActionDescriptor();
var colorDesc = new ActionDescriptor();
colorDesc.putDouble( charIDToTypeID('Rd '), sColor.rgb.red );
colorDesc.putDouble( charIDToTypeID('Grn '), sColor.rgb.green );
colorDesc.putDouble( charIDToTypeID('Bl '), sColor.rgb.blue );
fillDesc.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), colorDesc );
desc.putObject( charIDToTypeID('T '), stringIDToTypeID('solidColorLayer'), fillDesc );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
}
function getFillColor(){
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
var ref1= executeActionGet( ref );
var list = ref1.getList( charIDToTypeID( "Adjs" ) ) ;
var solidColorLayer = list.getObjectValue(0);
var color = solidColorLayer.getObjectValue(charIDToTypeID('Clr '));
var fillcolor = new SolidColor;
fillcolor.rgb.red = color.getDouble(charIDToTypeID('Rd '));
fillcolor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
fillcolor.rgb.blue = color.getDouble(charIDToTypeID('Bl '));
return fillcolor;
}
@kvaDrug
Copy link

kvaDrug commented Sep 21, 2015

@theinsanecow, maybe you know how to get color of of a shape?

@rtauler
Copy link

rtauler commented Jun 6, 2016

Hi, This doesn't work anymore with (at least) CC2015, the error goes to line 42, can you point out whats going on? or maybe fix it? It'll be amazing, thanks a lot.

@matheus0608
Copy link

Help with your code ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment