Created
March 31, 2011 04:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
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.
Help with your code ^^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@theinsanecow, maybe you know how to get color of of a shape?