Skip to main content
Participant
April 20, 2021
Question

Help modifying values of existing adjustment layer parameters with Javascript

  • April 20, 2021
  • 2 replies
  • 516 views

Hi all, I was hoping to get a bit of help setting up some bits of javascript I hoped would be relatively simple.

 

Essentially I want a script that simply takes the parameter values of a Levels adjustment layer for example, and adds or removes '10' from the Input, Gamma and Output (of RGB composite and/or individual channels).

 

For example, I got as far as this for changing the opacity of a layer down by 10%:

 

var opac = Math.round(app.activeDocument.activeLayer.opacity)
app.activeDocument.activeLayer.opacity = opac -10;

 

The idea is that I could hook this up to panel buttons  [-Opacity] and [+Opacity] for example, to quickly drop or increase a layer's opacity by set amounts from a UI button.

 

I'd like to do this for a Levels adjustment layer too. Buttons/scripts that could be things like '+Red' , '-Red' , '+ RGB Gamma' , '-Blue Gamma' etc.

 

I tried the script listener approach but I can only figure out how to make explicit values, rather than being able to simply add or remove from the existing values like my opacity snippet above. It's also a shame actions are not able to change values relative to the existing settings, and instead only setting absolute numbers.

 

Is this possible without a lot of work? I can't imagine why it should be for something so simple in my mind - especially as is the case with the opacity snippet above that can be done in two lines. I'm pretty fresh to scripting in Photoshop, but can hopefully keep up with simple scripts!

 

P.S. I had a look at this thread but I'm not sure I'm able to put two and two together to do what I'm asking here with that information.

 

This topic has been closed for replies.

2 replies

Kukurykus
Legend
April 21, 2021

You could do it for Color Balance using Adjustement Layers from 'legacyContentData'.

For levels browse forum for .fromStream() & .toStream() methods, what's complex too 😉

Chuck Uebele
Community Expert
Community Expert
April 20, 2021

Use code like this. Just replace the values that you get with ScriptListener with variables that you can replace when you call the function. To do each channel, you will have to record ScriptListner for each channel. I only did the RGB channel. As far as getting previous values, I'm not too good an getting those with AM code. You also need to either create an adjustment layer to be able to edit the values first.

 

 

doLeveles (15, 0, 1, 240, 255)

function doLeveles(shadowInput, shadowOutput, gamma, highlightInput, highlightOutput){
    var desc6 = new ActionDescriptor();
        var idpresetKind = stringIDToTypeID( "presetKind" );
        var idpresetKindType = stringIDToTypeID( "presetKindType" );
        var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );
        desc6.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
        var idAdjs = charIDToTypeID( "Adjs" );
            var list1 = new ActionList();
                var desc7 = new ActionDescriptor();
                var idChnl = charIDToTypeID( "Chnl" );
                    var ref1 = new ActionReference();
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idCmps = charIDToTypeID( "Cmps" );
                    ref1.putEnumerated( idChnl, idChnl, idCmps );
                desc7.putReference( idChnl, ref1 );
                var idInpt = charIDToTypeID( "Inpt" );
                    var list2 = new ActionList();
                    list2.putInteger( shadowInput );
                    list2.putInteger( highlightInput );
                desc7.putList( idInpt, list2 );
                var idGmm = charIDToTypeID( "Gmm " );
                desc7.putDouble( idGmm, famma );
                var idOtpt = charIDToTypeID( "Otpt" );
                    var list3 = new ActionList();
                    list3.putInteger( shadowOutput );
                    list3.putInteger( highlightOutput );
                desc7.putList( idOtpt, list3 );
            var idLvlA = charIDToTypeID( "LvlA" );
            list1.putObject( idLvlA, desc7 );
        desc6.putList( idAdjs, list1 );
    executeAction( idLvls, desc6, DialogModes.NO );
}