The following script will set the fill colour of all (multiple) selected solid or shape layers to the same foreground colour picker value. It offers a single undo history step. It's late here, so I'll need to add some other basic checks later in an updated 1.1 version.
/*
Change Fill Colour Of All Selected Layers.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/set-shape-color-with-colorpicker-or-foregroundcolor-script/td-p/14267798
v1.0, 30th November 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Store the current foreground colour
var savedForegroundColor = app.foregroundColor;
// Foreground colour picker stuff
getColorpickerColor();
var fColor = app.foregroundColor;
var rValue = fColor.rgb.red.toFixed(2);
var gValue = fColor.rgb.green.toFixed(2);
var bValue = fColor.rgb.blue.toFixed(2);
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Add check for color fill layer
if (activeDocument.activeLayer.kind == LayerKind.SOLIDFILL) {
// Set the colour
setColorFill(rValue, gValue, bValue);
} else {
//alert("The active layer isn't a Color Fill layer!");
}
}
// Finish the loop
// Restore the original foreground colour
app.foregroundColor = savedForegroundColor;
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
}
// Single history stage undo
activeDocument.suspendHistory("Undo script...", "main()");
///// FUNCTIONS /////
function getColorpickerColor() {
if (app.showColorPicker()) {
return app.foregroundColor;
} else {
return false;
}
}
function setColorFill(red, grain, blue) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("contentLayer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("null"), reference);
descriptor3.putDouble(s2t("red"), red);
descriptor3.putDouble(s2t("grain"), grain);
descriptor3.putDouble(s2t("blue"), blue);
descriptor2.putObject(s2t("color"), s2t("RGBColor"), descriptor3);
descriptor.putObject(s2t("to"), s2t("solidColorLayer"), descriptor2);
executeAction(s2t("set"), descriptor, DialogModes.NO);
}