Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Forked from theinsanecow/ChangeColor.jsx
Last active April 21, 2019 23:01
Show Gist options
  • Save Arahnoid/813e0e7e304422c501ce680f4b4a102c to your computer and use it in GitHub Desktop.
Save Arahnoid/813e0e7e304422c501ce680f4b4a102c to your computer and use it in GitHub Desktop.
[Update shape color] 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 #Photoshop
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment