• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[Script] Get HSL values in Hue/Saturation Layer

Community Beginner ,
Apr 15, 2024 Apr 15, 2024

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.

TOPICS
Actions and scripting

Views

543

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 15, 2024 Apr 15, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

Here 
It probably won't work in the new Photoshop.
Need another method. I can't check anything.
 
 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2024 Apr 17, 2024

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! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 17, 2024 Apr 17, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 15, 2024 Apr 15, 2024

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

 

 

 

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 16, 2024 Apr 16, 2024

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

 

 

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

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_Barranca

 
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?
 
 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 16, 2024 Apr 16, 2024

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?

 

 

 

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

Well, that means everything is fine with this in UXP or it’s just been fixed.
Thanks for the answer.
 
 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines