Copy link to clipboard
Copied
How can I change the color of layer style color overlay, but using as reference the color from foreground color? Let's say I have a color overlay as 30% opacity and red. And I want to change it to the blue that is on my foreground color. Which class should I look for when dealing with color overlay from layer style?
Thanks in advance.
OK, thanks to @jazz-y (the link to the original topic is in the code), I believe that I have a workable solution:
/*
Change only the colour overlay layer style effect to the foreground colour
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-change-the-color-of-layer-style-color-overlay-from-foreground-color/td-p/13726891
*/
#target photoshop
var rValue = app.foregroundColor.rgb.red.toFixed(2),
gValue = app.foregroundColor.rgb.green.toFixed(2),
bValue = app.foregr
...
Copy link to clipboard
Copied
This isn't covered in the DOM. How Adobe implemented Layer Styles is tricky, we can't always use the "simple" Action Manager (AM) code generated by ScriptingListener verbatim, as it records the entire layer styles, when all we wish to do is change a single property of a single effect.
You will need to use some advanced Action Manager code.
Searching the forum or web would be a good place to start.
To get the R, G, B foreground colours as variables to "plug into" something:
var rValue = app.foregroundColor.rgb.red.toFixed(2);
var gValue = app.foregroundColor.rgb.green.toFixed(2);
var bValue = app.foregroundColor.rgb.blue.toFixed(2);
Copy link to clipboard
Copied
OK, thanks to @jazz-y (the link to the original topic is in the code), I believe that I have a workable solution:
/*
Change only the colour overlay layer style effect to the foreground colour
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-change-the-color-of-layer-style-color-overlay-from-foreground-color/td-p/13726891
*/
#target photoshop
var rValue = app.foregroundColor.rgb.red.toFixed(2),
gValue = app.foregroundColor.rgb.green.toFixed(2),
bValue = app.foregroundColor.rgb.blue.toFixed(2);
changeFill(rValue, gValue, bValue);
function changeFill(red, green, blue) {
/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/modify-a-layereffects-object/td-p/12170579#U12194548 */
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t("property"), p = s2t("layerEffects"));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
var fx = executeActionGet(r).hasKey(p) ? executeActionGet(r).getObjectValue(p) : new ActionDescriptor(),
currentFill = fx.hasKey(p = s2t("solidFill")) ? fx.getObjectValue(p) : new ActionDescriptor();
if (fx.hasKey(p = s2t("solidFillMulti"))) fx.erase(p);
(d = new ActionDescriptor()).putDouble(s2t("red"), red);
d.putDouble(s2t("green"), green);
d.putDouble(s2t("blue"), blue);
currentFill.putObject(s2t("color"), s2t("RGBColor"), d);
fx.putObject(s2t("solidFill"), s2t("solidFill"), currentFill);
(r = new ActionReference()).putProperty(s2t("property"), s2t("layerEffects"));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
(d = new ActionDescriptor()).putReference(s2t("null"), r);
d.putObject(s2t("to"), s2t("layerEffects"), fx);
executeAction(s2t("set"), d, DialogModes.NO);
}
Copy link to clipboard
Copied
thanks A LOT!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If I understand the question, another way is:
-click on "Color Overlay"
-Choose the blue foreground color
The other elements of the style (gradient, bevel & emboss, etc whatever they were) remain unchanged. As to the opacity issue, adjust the slider. If this isn't what you meant, maybe post a screenshot?
Copy link to clipboard
Copied
@Leslie Moak Murray – It's easy to miss the topic label/tag sometimes, this is a scripting question.
Copy link to clipboard
Copied
Well yes, but sometimes it seems to me there are easier ways (I am a Blonde Person.The very word "script" fills me with anxiety).
Copy link to clipboard
Copied
That's funny, Leslie! 🤣 (I'm not a scripter either)