Skip to main content
Andre Nguyen
Inspiring
April 15, 2024
Question

[Script] Get HSL values in Hue/Saturation Layer

  • April 15, 2024
  • 3 replies
  • 1516 views

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.

This topic has been closed for replies.

3 replies

Davide_Barranca12040269
Community Expert
Community Expert
April 15, 2024

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);

 

 

 

Davide Barranca - PS developer and authorwww.ps-scripting.com
Legend
April 15, 2024
Davide_Barranca, can I ask you to check?
On any image, create a Curves layer. Click the "Auto" button.
Make sure the values have changed.
Without touching anything with your hands in this correction, can you read the values of the curve points?
Davide_Barranca12040269
Community Expert
Community Expert
April 16, 2024
quote

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

 

By @Davide_Barranca12040269

 
I didn't ask how to do this. I asked you to do this practically and tell me the result. Can you get the curve points provided that the "Auto" button was pressed?
Do you have a solution?
 
 
 

Hi @r-bin,

I can get the curve points, indeed—see the attached video. Is this what you originally meant?

 

 

 

Davide Barranca - PS developer and authorwww.ps-scripting.com
Legend
April 15, 2024
Here 
It probably won't work in the new Photoshop.
Need another method. I can't check anything.
 
 
 
Andre Nguyen
Inspiring
April 17, 2024

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! 

Stephen Marsh
Community Expert
Community Expert
April 15, 2024

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.