Copy link to clipboard
Copied
I was wondering if anyone knows a way to get the current hue saturation and lightness values from a hue/saturation layer. I want to be able to get the HSL in a Hue/Saturation adjustment layer and then do something with those values, but I have yet to find a way to read those values in Javascript.
Copy link to clipboard
Copied
This will take advanced knowledge of ExtendScript Action Manager coding, or perhaps UXP batchPlay coding. There are probably a handful of forum regulars with this knowledge, which is beyond me.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks god, I think I've found the answer, and the answer is based on your script @r-bin on this topic:
ps-javascript-get-brig-amp-contrast-values-no-data
function getHueSaturationDesc(id) {
try {
var r = new ActionReference();
var d = new ActionDescriptor();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putInteger(stringIDToTypeID("layerID"), id);
d.putBoolean(stringIDToTypeID("layerInfo"), true);
d.putBoolean(stringIDToTypeID("includeAncestors"), false);
eval("var json=" + executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));
var d = new ActionDescriptor();
if (!json.layers) return d;
if (json.layers.length != 1) return d;
if (json.layers[0].id != id) return d;
var adj = json.layers[0].adjustment;
alert(adj.toSource());
return d;
} catch (e) {
throw e;
}
}
// Use the function within your document and layer checks
if (app.documents.length > 0) {
var doc = app.activeDocument;
if (doc.activeLayer) {
var activeLayer = doc.activeLayer;
// Check if the active layer is a Hue/Saturation adjustment layer
if (activeLayer.kind === LayerKind.HUESATURATION) {
getHueSaturationDesc(activeLayer.id);
} else {
alert("The active layer is not a Hue/Saturation adjustment layer.");
}
} else {
alert("No active layer is selected.");
}
} else {
alert("No document is open.");
}
You're awesome, thank you!
Copy link to clipboard
Copied
Could you edit the answer to this link "ps-javascript-get-brig-amp-contrast-values-no-data" as it references your answer, so I can mark this as the correct answer
Copy link to clipboard
Copied
Hiya,
This would work as a UXP script (or within a UXP plugin) when the Hue/Sat Adjustment Layer is the currently selected layer.
const { batchPlay } = require("photoshop").action;
const res = await batchPlay([{
_obj: "get",
_target: [
{ _property: "adjustment" },
{ _ref: "layer", _enum: "ordinal", _value: "targetEnum" }
]}
],{});
const { hue, saturation, lightness } = res[0].adjustment[0].adjustment[0];
console.log(hue, saturation, lightness);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi!
It won't work for a Curve: the original question was for a Hue/Sat layer.
If you need the points of the composite channels of a Curve, you'd have to get the `adjustment` property via BatchPlay in the same way, but then look for:
res[0].adjustment[0].adjustment[0].curve
// 👆 an array of object with { horizontal, vertical } props
Copy link to clipboard
Copied
Hi!
It won't work for a Curve: the original question was for a Hue/Sat layer.
If you need the points of the composite channels of a Curve, you'd have to get the `adjustment` property via BatchPlay in the same way, but then look for:
res[0].adjustment[0].adjustment[0].curve
// an array of object with { horizontal, vertical } props
Copy link to clipboard
Copied
Hi @r-bin,
I can get the curve points, indeed—see the attached video. Is this what you originally meant?
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now