Skip to main content
David André Erichsen
Inspiring
December 28, 2022
Answered

add adjustment layer

  • December 28, 2022
  • 8 replies
  • 702 views

Why does not "kind:levels layer" work - but kind:normal works?

 

tell application "Adobe Photoshop 2023"
tell current document
set newlayerproperties to {kind:levels layer, grouped:false, background layer:false}
set x to make new art layer with properties newlayerproperties
end tell
end tell

 

From the documentastion: 

kind (black and white layer/‌brightness contrast layer/‌channel mixer layer/‌color balance layer/‌color lookup/‌curves layer/‌exposure layer/‌gradient fill layer/‌gradient map layer/‌hue saturation layer/‌inversion layer/‌levels layer/‌normal/‌pattern fill layer/‌photo filter layer/‌posterize layer/‌selective color layer/‌smart object layer/‌solid fill layer/‌text layer/‌threeD layer/‌threshold layer/‌vibrance layer/‌video layer) : to create a text layer set this property to 'text layer' on an empty art layer of type 'normal'

This topic has been closed for replies.
Correct answer Stephen Marsh

The SL plug-in writes to a log file on the desktop. If you are using Photoshop 2023 version it may not work. It didn't for me but works in 2022 and 2021 versions.

 

It records/writes a lot of junk, so best to do one step at a time, isolate the required code and clear or delete the log each time before you need something.

 

https://youtu.be/x_rMhCz-MdQ

8 replies

David André Erichsen
Inspiring
December 29, 2022

Thank you! You have been very helpfull!

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
December 29, 2022

The SL plug-in writes to a log file on the desktop. If you are using Photoshop 2023 version it may not work. It didn't for me but works in 2022 and 2021 versions.

 

It records/writes a lot of junk, so best to do one step at a time, isolate the required code and clear or delete the log each time before you need something.

 

https://youtu.be/x_rMhCz-MdQ

David André Erichsen
Inspiring
December 29, 2022

Thanks! I did not know about that plug in. I have installed it now, but how do I get that code from it?

Stephen Marsh
Community Expert
Community Expert
December 29, 2022
quote

I have tried, but haven't got JS to work either. Do you have code that works?


By @David André Erichsen

 

 

Take a look at the previous AM code for creating a new levels adjustment layer, in the first line:

 

var idmake = stringIDToTypeID( "make" );

 

There are double quote " marks, which would need to be escaped with a backslash to be used in an AppleScript reference:

 

var idmake = stringIDToTypeID( \"make\" );

 

Then you could use the code as follows in AS:

 

tell application "Adobe Photoshop 2023"
	set js to "var idmake = stringIDToTypeID( \"make\" );
    var desc772 = new ActionDescriptor();
    var idnull = stringIDToTypeID( \"null\" );
        var ref170 = new ActionReference();
        var idadjustmentLayer = stringIDToTypeID( \"adjustmentLayer\" );
        ref170.putClass( idadjustmentLayer );
    desc772.putReference( idnull, ref170 );
    var idusing = stringIDToTypeID( \"using\" );
        var desc773 = new ActionDescriptor();
        var idtype = stringIDToTypeID( \"type\" );
            var desc774 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( \"presetKind\" );
            var idpresetKindType = stringIDToTypeID( \"presetKindType\" );
            var idpresetKindDefault = stringIDToTypeID( \"presetKindDefault\" );
            desc774.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idlevels = stringIDToTypeID( \"levels\" );
        desc773.putObject( idtype, idlevels, desc774 );
    var idadjustmentLayer = stringIDToTypeID( \"adjustmentLayer\" );
    desc772.putObject( idusing, idadjustmentLayer, desc773 );
executeAction( idmake, desc772, DialogModes.NO );"
	do javascript js
end tell

 

Note that the AM JS code is enclosed in " quote marks inside the AS code, which is why one must escape the \" marks in the JS code.

Stephen Marsh
Community Expert
Community Expert
December 29, 2022

Even in JS, there are limitations... The following creates a new normal layer, then converts it to a text layer...

 

var myLayer = activeDocument.artLayers.add();
myLayer.kind = LayerKind.TEXT;

 

However, it doesn't work for an adjustment layer such as levels:

 

var myLayer = activeDocument.artLayers.add();
myLayer.kind = LayerKind.LEVELS;

 

So one has to use Action Manager (AM) code for anything not covered under the standard DOM code, most commonly created with the ScriptingListener plug-in or written by hand, which a small group of user can do without the plugin. 

 

var idmake = stringIDToTypeID( "make" );
    var desc772 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref170 = new ActionReference();
        var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
        ref170.putClass( idadjustmentLayer );
    desc772.putReference( idnull, ref170 );
    var idusing = stringIDToTypeID( "using" );
        var desc773 = new ActionDescriptor();
        var idtype = stringIDToTypeID( "type" );
            var desc774 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( "presetKind" );
            var idpresetKindType = stringIDToTypeID( "presetKindType" );
            var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
            desc774.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idlevels = stringIDToTypeID( "levels" );
        desc773.putObject( idtype, idlevels, desc774 );
    var idadjustmentLayer = stringIDToTypeID( "adjustmentLayer" );
    desc772.putObject( idusing, idadjustmentLayer, desc773 );
executeAction( idmake, desc772, DialogModes.NO );
David André Erichsen
Inspiring
December 29, 2022

I have tried, but haven't got JS to work either. Do you have code that works?

Stephen Marsh
Community Expert
Community Expert
December 29, 2022

I don't code in AppleScript, however, as a last resort, it is possible to use a snippet of JavaScript code in the AS code to perform the required step if you can't get it to work using native AS code.

 

EDIT: A quick look at the AS reference for "art layer kind":

 

"Sets the layer’s kind (such as 'text layer').
Note: You can use the kind property to make a background layer a normal layer; however, to make a layer a background layer, you must use background layer.
Note: Valid only when the layer is empty and when background layer is false. See background layer."

 

Perhaps you first need to add a blank normal art layer, then change it's kind to the required adjustment layer?