How to add a drop shadow to a layer using scripts..
Copy link to clipboard
Copied
Hello all
I am trying to add a drop shadow Layer Style to an active layer using scripts but cannot find anything specifically for this... any tips?
I have tried applyStyle but cannot get it to work correctly.
Would be nice if I could adjust stuff like the angle/opacticy/size etc.
Thanks in advance.
Explore related tutorials & articles
Copy link to clipboard
Copied
You'll need the Scripting Listener plug-in for anything outside of the "standard" code as listed in the JS reference:
And this often helps as well:
https://github.com/rendertom/Clean-SL
https://community.adobe.com/t5/photoshop/clean-sl/m-p/9358507
Copy link to clipboard
Copied
Raw SL recorded code:
var idsetd = charIDToTypeID( "setd" );
var desc677 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref90 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idLefx = charIDToTypeID( "Lefx" );
ref90.putProperty( idPrpr, idLefx );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref90.putEnumerated( idLyr, idOrdn, idTrgt );
desc677.putReference( idnull, ref90 );
var idT = charIDToTypeID( "T " );
var desc678 = new ActionDescriptor();
var idScl = charIDToTypeID( "Scl " );
var idPrc = charIDToTypeID( "#Prc" );
desc678.putUnitDouble( idScl, idPrc, 416.666667 );
var idDrSh = charIDToTypeID( "DrSh" );
var desc679 = new ActionDescriptor();
var idenab = charIDToTypeID( "enab" );
desc679.putBoolean( idenab, true );
var idpresent = stringIDToTypeID( "present" );
desc679.putBoolean( idpresent, true );
var idshowInDialog = stringIDToTypeID( "showInDialog" );
desc679.putBoolean( idshowInDialog, true );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc679.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( "Clr " );
var desc680 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc680.putDouble( idRd, 0.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc680.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc680.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc679.putObject( idClr, idRGBC, desc680 );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc679.putUnitDouble( idOpct, idPrc, 10.000000 );
var iduglg = charIDToTypeID( "uglg" );
desc679.putBoolean( iduglg, true );
var idlagl = charIDToTypeID( "lagl" );
var idAng = charIDToTypeID( "#Ang" );
desc679.putUnitDouble( idlagl, idAng, 90.000000 );
var idDstn = charIDToTypeID( "Dstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc679.putUnitDouble( idDstn, idPxl, 20.000000 );
var idCkmt = charIDToTypeID( "Ckmt" );
var idPxl = charIDToTypeID( "#Pxl" );
desc679.putUnitDouble( idCkmt, idPxl, 5.000000 );
var idblur = charIDToTypeID( "blur" );
var idPxl = charIDToTypeID( "#Pxl" );
desc679.putUnitDouble( idblur, idPxl, 50.000000 );
var idNose = charIDToTypeID( "Nose" );
var idPrc = charIDToTypeID( "#Prc" );
desc679.putUnitDouble( idNose, idPrc, 5.000000 );
var idAntA = charIDToTypeID( "AntA" );
desc679.putBoolean( idAntA, false );
var idTrnS = charIDToTypeID( "TrnS" );
var desc681 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc681.putString( idNm, """Linear""" );
var idShpC = charIDToTypeID( "ShpC" );
desc679.putObject( idTrnS, idShpC, desc681 );
var idlayerConceals = stringIDToTypeID( "layerConceals" );
desc679.putBoolean( idlayerConceals, true );
var idDrSh = charIDToTypeID( "DrSh" );
desc678.putObject( idDrSh, idDrSh, desc679 );
var idgagl = charIDToTypeID( "gagl" );
var idAng = charIDToTypeID( "#Ang" );
desc678.putUnitDouble( idgagl, idAng, -90.000000 );
var idLefx = charIDToTypeID( "Lefx" );
desc677.putObject( idT, idLefx, desc678 );
executeAction( idsetd, desc677, DialogModes.NO );
Same code passed through the Clean SL script:
set(416.666667, true, true, true, 0, 0, 0, 10, true, 90, 20, 5, 50, 5, false, "Linear", true, -90);
function set(scale, enabled, present, showInDialog, red, Grn, blue, opacity, useGlobalAngle, localLightingAngle, distance, chokeMatte, blur, noise, AntA, name2, layerConceals, globalLightingAngle) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var descriptor4 = new ActionDescriptor();
var descriptor5 = new ActionDescriptor();
var reference = new ActionReference();
reference.putProperty( s2t( "property" ), s2t( "layerEffects" ));
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( c2t( "null" ), reference );
descriptor2.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), scale );
descriptor3.putBoolean( s2t( "enabled" ), enabled );
descriptor3.putBoolean( s2t( "present" ), present );
descriptor3.putBoolean( s2t( "showInDialog" ), showInDialog );
descriptor3.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( "normal" ));
descriptor4.putDouble( s2t( "red" ), red );
descriptor4.putDouble( c2t( "Grn " ), Grn );
descriptor4.putDouble( s2t( "blue" ), blue );
descriptor3.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor4 );
descriptor3.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), opacity );
descriptor3.putBoolean( s2t( "useGlobalAngle" ), useGlobalAngle );
descriptor3.putUnitDouble( s2t( "localLightingAngle" ), s2t( "angleUnit" ), localLightingAngle );
descriptor3.putUnitDouble( s2t( "distance" ), s2t( "pixelsUnit" ), distance );
descriptor3.putUnitDouble( s2t( "chokeMatte" ), s2t( "pixelsUnit" ), chokeMatte );
descriptor3.putUnitDouble( s2t( "blur" ), s2t( "pixelsUnit" ), blur );
descriptor3.putUnitDouble( s2t( "noise" ), s2t( "percentUnit" ), noise );
descriptor3.putBoolean( c2t( "AntA" ), AntA );
descriptor5.putString( s2t( "name" ), name2 );
descriptor3.putObject( c2t( "TrnS" ), c2t( "ShpC" ), descriptor5 );
descriptor3.putBoolean( s2t( "layerConceals" ), layerConceals );
descriptor2.putObject( s2t( "dropShadow" ), s2t( "dropShadow" ), descriptor3 );
descriptor2.putUnitDouble( s2t( "globalLightingAngle" ), s2t( "angleUnit" ), globalLightingAngle );
descriptor.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor2 );
executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}
Copy link to clipboard
Copied
Do you know how to install it? The instructions on those first links do not seem to apply to what I downloaded... also would this work with PS21?
Thank you
Copy link to clipboard
Copied
There are versions of the Adobe SL plug-in specifically for 2020, or 2019 or earlier. If 2021 is not listed, it may be too soon for the documentation to have caught up, or perhaps 2020 works, or perhaps not.
If you are referring to one of the many scripts to clean the SL code, it would depend on the script in question.
Copy link to clipboard
Copied
Hello, so sorry to be replying so late
For the code you sent, can I just copy paste it into my script to have it work, or would I need to change lines to fit the specifics of my layers? And if I could, would I do just the clean second section or both sections? Thanks so much.
Copy link to clipboard
Copied
Your choice on whether to use the raw code recording or use the alternative "cleaned" version...
Either way you will need to put in the values specific to your document, I just used random values.
Sometimes the raw recording is easier to work with. In this case I prefer the raw version as I think it is easier to see where the values "line up". Sometimes a raw recording does not work and needs to be wrapped in a function, which the clean SL script helps automate.
The Clean SL version has helpfully created a function, which is great if you need to call the function multiple times using different input values.

