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

Script listener assistance.

Engaged ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Hi,

This is the 1st time I use script listener though i already wrote quite a few scripts.

I wanted to add a drop shadow to a layer and tried the script listener.

I have  layers:

Layer 3, Layer 1 & TEST.

I recorded only the following actions:

1. Select layer TEST

2. apply only drop shadow

I go the following result from script listener.

What are the basic steps i need to perform in order to implement this in my script, turning it into a function which adds drop shadow?

Thanks

// =======================================================

var idslct = charIDToTypeID( "slct" );

    var desc48 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref22 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        ref22.putName( idLyr, "TEST" );

    desc48.putReference( idnull, ref22 );

    var idMkVs = charIDToTypeID( "MkVs" );

    desc48.putBoolean( idMkVs, false );

    var idLyrI = charIDToTypeID( "LyrI" );

        var list12 = new ActionList();

        list12.putInteger( 6 );

    desc48.putList( idLyrI, list12 );

executeAction( idslct, desc48, DialogModes.NO );

// =======================================================

var idmodalStateChanged = stringIDToTypeID( "modalStateChanged" );

    var desc49 = new ActionDescriptor();

    var idLvl = charIDToTypeID( "Lvl " );

    desc49.putInteger( idLvl, 1 );

    var idStte = charIDToTypeID( "Stte" );

    var idStte = charIDToTypeID( "Stte" );

    var identer = stringIDToTypeID( "enter" );

    desc49.putEnumerated( idStte, idStte, identer );

    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

    desc49.putBoolean( idkcanDispatchWhileModal, true );

    var idTtl = charIDToTypeID( "Ttl " );

    desc49.putString( idTtl, """Layer Style""" );

executeAction( idmodalStateChanged, desc49, DialogModes.NO );

// =======================================================

var idmodalStateChanged = stringIDToTypeID( "modalStateChanged" );

    var desc50 = new ActionDescriptor();

    var idLvl = charIDToTypeID( "Lvl " );

    desc50.putInteger( idLvl, 0 );

    var idStte = charIDToTypeID( "Stte" );

    var idStte = charIDToTypeID( "Stte" );

    var idexit = stringIDToTypeID( "exit" );

    desc50.putEnumerated( idStte, idStte, idexit );

    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

    desc50.putBoolean( idkcanDispatchWhileModal, true );

    var idTtl = charIDToTypeID( "Ttl " );

    desc50.putString( idTtl, """Layer Style""" );

executeAction( idmodalStateChanged, desc50, DialogModes.NO );

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc51 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref23 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idLefx = charIDToTypeID( "Lefx" );

        ref23.putProperty( idPrpr, idLefx );

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref23.putEnumerated( idLyr, idOrdn, idTrgt );

    desc51.putReference( idnull, ref23 );

    var idT = charIDToTypeID( "T   " );

        var desc52 = new ActionDescriptor();

        var idScl = charIDToTypeID( "Scl " );

        var idPrc = charIDToTypeID( "#Prc" );

        desc52.putUnitDouble( idScl, idPrc, 416.666667 );

        var idDrSh = charIDToTypeID( "DrSh" );

            var desc53 = new ActionDescriptor();

            var idenab = charIDToTypeID( "enab" );

            desc53.putBoolean( idenab, true );

            var idpresent = stringIDToTypeID( "present" );

            desc53.putBoolean( idpresent, true );

            var idshowInDialog = stringIDToTypeID( "showInDialog" );

            desc53.putBoolean( idshowInDialog, true );

            var idMd = charIDToTypeID( "Md  " );

            var idBlnM = charIDToTypeID( "BlnM" );

            var idMltp = charIDToTypeID( "Mltp" );

            desc53.putEnumerated( idMd, idBlnM, idMltp );

            var idClr = charIDToTypeID( "Clr " );

                var desc54 = new ActionDescriptor();

                var idRd = charIDToTypeID( "Rd  " );

                desc54.putDouble( idRd, 0.000000 );

                var idGrn = charIDToTypeID( "Grn " );

                desc54.putDouble( idGrn, 0.000000 );

                var idBl = charIDToTypeID( "Bl  " );

                desc54.putDouble( idBl, 0.000000 );

            var idRGBC = charIDToTypeID( "RGBC" );

            desc53.putObject( idClr, idRGBC, desc54 );

            var idOpct = charIDToTypeID( "Opct" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc53.putUnitDouble( idOpct, idPrc, 35.000000 );

            var iduglg = charIDToTypeID( "uglg" );

            desc53.putBoolean( iduglg, true );

            var idlagl = charIDToTypeID( "lagl" );

            var idAng = charIDToTypeID( "#Ang" );

            desc53.putUnitDouble( idlagl, idAng, 90.000000 );

            var idDstn = charIDToTypeID( "Dstn" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc53.putUnitDouble( idDstn, idPxl, 5.000000 );

            var idCkmt = charIDToTypeID( "Ckmt" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc53.putUnitDouble( idCkmt, idPxl, 1.000000 );

            var idblur = charIDToTypeID( "blur" );

            var idPxl = charIDToTypeID( "#Pxl" );

            desc53.putUnitDouble( idblur, idPxl, 5.000000 );

            var idNose = charIDToTypeID( "Nose" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc53.putUnitDouble( idNose, idPrc, 0.000000 );

            var idAntA = charIDToTypeID( "AntA" );

            desc53.putBoolean( idAntA, false );

            var idTrnS = charIDToTypeID( "TrnS" );

                var desc55 = new ActionDescriptor();

                var idNm = charIDToTypeID( "Nm  " );

                desc55.putString( idNm, """Linear""" );

            var idShpC = charIDToTypeID( "ShpC" );

            desc53.putObject( idTrnS, idShpC, desc55 );

            var idlayerConceals = stringIDToTypeID( "layerConceals" );

            desc53.putBoolean( idlayerConceals, true );

        var idDrSh = charIDToTypeID( "DrSh" );

        desc52.putObject( idDrSh, idDrSh, desc53 );

    var idLefx = charIDToTypeID( "Lefx" );

    desc51.putObject( idT, idLefx, desc52 );

executeAction( idsetd, desc51, DialogModes.NO );

TOPICS
Actions and scripting

Views

1.7K

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

correct answers 1 Correct answer

Community Expert , Jul 09, 2019 Jul 09, 2019

Yes first you add a layer or select a layer that will be the target layer the function add the style to.  In my Toolkig package I distribute Text Layer styles and Image  Layer styles my script  can use and a preferences script users can add styles for my scripts to use by editing the Phot Collage Toolkit preference script "PCTpreferences.jsx". The style list for the scripts pull down menus are set from it..

]

////////////////////////////////////////////////////////////////////////////////////////

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Run it through the Clean SL script:

Clean SL

Which works 90% of the time, however it is not always that easy...

The following edited code adds the effect only to the currently targeted layer:

select();

function select() {

  var c2t = function (s) {

  return app.charIDToTypeID(s);

  };

  var s2t = function (s) {

  return app.stringIDToTypeID(s);

  };

  var descriptor2 = new ActionDescriptor();

  var descriptor3 = new ActionDescriptor();

  var descriptor4 = new ActionDescriptor();

  var descriptor5 = new ActionDescriptor();

  var descriptor6 = new ActionDescriptor();

  var descriptor7 = new ActionDescriptor();

  var descriptor8 = new ActionDescriptor();

  var list = new ActionList();

  var reference = new ActionReference();

  var reference2 = new ActionReference();

  // =======================================================

  reference2.putProperty( s2t( "property" ), s2t( "layerEffects" ));

  reference2.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));

  descriptor4.putReference( c2t( "null" ), reference2 );

  descriptor5.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), 416.666667 );

  descriptor6.putBoolean( s2t( "enabled" ), true );

  descriptor6.putBoolean( s2t( "present" ), true );

  descriptor6.putBoolean( s2t( "showInDialog" ), true );

  descriptor6.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( "multiply" ));

  descriptor7.putDouble( s2t( "red" ), 0.000000 );

  descriptor7.putDouble( c2t( "Grn " ), 0.000000 );

  descriptor7.putDouble( s2t( "blue" ), 0.000000 );

  descriptor6.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor7 );

  descriptor6.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), 35.000000 );

  descriptor6.putBoolean( s2t( "useGlobalAngle" ), true );

  descriptor6.putUnitDouble( s2t( "localLightingAngle" ), s2t( "angleUnit" ), 90.000000 );

  descriptor6.putUnitDouble( s2t( "distance" ), s2t( "pixelsUnit" ), 5.000000 );

  descriptor6.putUnitDouble( s2t( "chokeMatte" ), s2t( "pixelsUnit" ), 1.000000 );

  descriptor6.putUnitDouble( s2t( "blur" ), s2t( "pixelsUnit" ), 5.000000 );

  descriptor6.putUnitDouble( s2t( "noise" ), s2t( "percentUnit" ), 0.000000 );

  descriptor6.putBoolean( c2t( "AntA" ), false );

  descriptor8.putString( s2t( "name" ), "Linear" );

  descriptor6.putObject( c2t( "TrnS" ), c2t( "ShpC" ), descriptor8 );

  descriptor6.putBoolean( s2t( "layerConceals" ), true );

  descriptor5.putObject( s2t( "dropShadow" ), s2t( "dropShadow" ), descriptor6 );

  descriptor4.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor5 );

  executeAction( s2t( "set" ), descriptor4, DialogModes.NO );

}

And here was the original code, before I chopped off some code that was causing the script to hang (I did not attempt to isolate which chunk of code was problematic):

select();

function select() {

  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 descriptor6 = new ActionDescriptor();

  var descriptor7 = new ActionDescriptor();

  var descriptor8 = new ActionDescriptor();

  var list = new ActionList();

  var reference = new ActionReference();

  var reference2 = new ActionReference();

  // =======================================================

  reference.putName( s2t( "layer" ), "TEST" );

  descriptor.putReference( c2t( "null" ), reference );

  descriptor.putBoolean( s2t( "makeVisible" ), false );

  list.putInteger( 6 );

  descriptor.putList( s2t( "layerID" ), list );

  executeAction( s2t( "select" ), descriptor, DialogModes.NO );

  // =======================================================

  descriptor2.putInteger( s2t( "level" ), 1 );

  descriptor2.putEnumerated( s2t( "state" ), s2t( "state" ), s2t( "enter" ));

  descriptor2.putBoolean( s2t( "kcanDispatchWhileModal" ), true );

  descriptor2.putString( s2t( "title" ), "Layer Style" );

  executeAction( s2t( "modalStateChanged" ), descriptor2, DialogModes.NO );

  // =======================================================

  descriptor3.putInteger( s2t( "level" ), 0 );

  descriptor3.putEnumerated( s2t( "state" ), s2t( "state" ), s2t( "exit" ));

  descriptor3.putBoolean( s2t( "kcanDispatchWhileModal" ), true );

  descriptor3.putString( s2t( "title" ), "Layer Style" );

  executeAction( s2t( "modalStateChanged" ), descriptor3, DialogModes.NO );

  // =======================================================

  reference2.putProperty( s2t( "property" ), s2t( "layerEffects" ));

  reference2.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));

  descriptor4.putReference( c2t( "null" ), reference2 );

  descriptor5.putUnitDouble( s2t( "scale" ), s2t( "percentUnit" ), 416.666667 );

  descriptor6.putBoolean( s2t( "enabled" ), true );

  descriptor6.putBoolean( s2t( "present" ), true );

  descriptor6.putBoolean( s2t( "showInDialog" ), true );

  descriptor6.putEnumerated( s2t( "mode" ), s2t( "blendMode" ), s2t( "multiply" ));

  descriptor7.putDouble( s2t( "red" ), 0.000000 );

  descriptor7.putDouble( c2t( "Grn " ), 0.000000 );

  descriptor7.putDouble( s2t( "blue" ), 0.000000 );

  descriptor6.putObject( s2t( "color" ), s2t( "RGBColor" ), descriptor7 );

  descriptor6.putUnitDouble( s2t( "opacity" ), s2t( "percentUnit" ), 35.000000 );

  descriptor6.putBoolean( s2t( "useGlobalAngle" ), true );

  descriptor6.putUnitDouble( s2t( "localLightingAngle" ), s2t( "angleUnit" ), 90.000000 );

  descriptor6.putUnitDouble( s2t( "distance" ), s2t( "pixelsUnit" ), 5.000000 );

  descriptor6.putUnitDouble( s2t( "chokeMatte" ), s2t( "pixelsUnit" ), 1.000000 );

  descriptor6.putUnitDouble( s2t( "blur" ), s2t( "pixelsUnit" ), 5.000000 );

  descriptor6.putUnitDouble( s2t( "noise" ), s2t( "percentUnit" ), 0.000000 );

  descriptor6.putBoolean( c2t( "AntA" ), false );

  descriptor8.putString( s2t( "name" ), "Linear" );

  descriptor6.putObject( c2t( "TrnS" ), c2t( "ShpC" ), descriptor8 );

  descriptor6.putBoolean( s2t( "layerConceals" ), true );

  descriptor5.putObject( s2t( "dropShadow" ), s2t( "dropShadow" ), descriptor6 );

  descriptor4.putObject( s2t( "to" ), s2t( "layerEffects" ), descriptor5 );

  executeAction( s2t( "set" ), descriptor4, DialogModes.NO );

}

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 Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Yes the scriptlistener in newer version of Photoshop records some steps the only seem to work when you actually use Photoshop UI.   I called these steps junk code.  Tomas Å inkÅ«nas the Programmer author os  Clean SL.JSX was kind and added code That came remove this Junk from the listener log for me.   His code is easy to modify if Additional junk stepe are added in the future you just need to add he new junk step name toe the junk array

junkArray: [

"stringIDToTypeID( \"convertJSONdescriptor\" );",

"stringIDToTypeID( \"invokeCommand\" );",

"stringIDToTypeID( \"modalHTMLPending\" );",

"stringIDToTypeID( \"modalStateChanged\" );",

"stringIDToTypeID( \"toggleSearch\" );",

"stringIDToTypeID( \"toolModalStateChanged\" );"

],

You see the name toolModalStateChanged in your log.... If you remove the code your log may work in a script. 

About Layer styles.  If you add a layer style many of the setting in an effect a drop shadow will depend on the documents resolution and size.  Layer Styles add via the Layer Style Dialog will look different on different  resolution document if you do not scale the settings  for the current documents resolution.    Photoshop also has a feature  where Image Resize can scale styles and there is a menu item  menu Layer>Layer Style>Scale

You can also add layer style via the Style Palette to add Layer Styles Saved by name into the style Palette. When you add these Photoshop seem to scale then automatically for the current documents resolution.    Therefor, When I add Layer Styles in an Action or Script I normally will use the Style Palette method a name style.   Here is a function made from Action manager coed to add a layer style by style name.

addStyle("StyleName");

function addStyle(Style){

   var idASty = charIDToTypeID( "ASty" );

       var desc20 = new ActionDescriptor();

       var idnull = charIDToTypeID( "null" );

           var ref3 = new ActionReference();

           var idStyl = charIDToTypeID( "Styl" );

           ref3.putName( idStyl, Style );

       desc20.putReference( idnull, ref3 );

       var idT = charIDToTypeID( "T   " );

           var ref4 = new ActionReference();

           var idLyr = charIDToTypeID( "Lyr " );

           var idOrdn = charIDToTypeID( "Ordn" );

           var idTrgt = charIDToTypeID( "Trgt" );

           ref4.putEnumerated( idLyr, idOrdn, idTrgt );

       desc20.putReference( idT, ref4 );

   try{

      executeAction( idASty, desc20, DialogModes.NO);

   }catch(e){}

}

JJMack

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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Thank a lot!

That really helps

Concerning addStyle("StyleName");,

I assume it adds the style to the active layer, correct?

Another thing, where do you download "Clean SL" from? There is not download link in the link you pointed to at the top.

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 Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Yes first you add a layer or select a layer that will be the target layer the function add the style to.  In my Toolkig package I distribute Text Layer styles and Image  Layer styles my script  can use and a preferences script users can add styles for my scripts to use by editing the Phot Collage Toolkit preference script "PCTpreferences.jsx". The style list for the scripts pull down menus are set from it..

]

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////CUSTOMIZE Preferences Here////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Some Hard Coded variables that some day I may put into the dialog options area

var imageStyleList = ['Default Style (None)','Photo Collage Style 1','Photo Collage Style 2','Photo Collage Style 3','Photo Collage Style 4','Photo Collage Style 5','Photo Collage Style 6','Photo Collage Style 7','Photo Collage Style 8','Photo Collage Style 9','Photo Collage Style 10','Photo Collage Style 11'];

var imageStyleDefault = 0;       // imageStyleList index number

var textSizeFactor = 4;              // > 1 scales down text size

var textFont = "ArialMT";           // Photoshop internal font name

var textAngle = -10;                   // center text angle

var textColor = new SolidColor; // text color

    textColor.rgb.red = 255;

    textColor.rgb.green = 255;

    textColor.rgb.blue = 255;

var textStyleList = ['Default Style (None)','Shiny Metal','Shiney Metal No Stroke','Strong Metal','Strong Metal No Stroke','Clear Emboss - Inner Bevel','Clear Emboss - Outer Bevel','JJMack Overlay'];

var textStyleDefault = 0;                // textStyleList index number

var textLocationDefault = 7;          // text Location Default Bottom Center

//var templateFolder = "C:/Program Files/Adobe/Adobe Photoshop Templates/";

var templateFolder = "E:/Public Files/Pictures/Adobe Photoshop Templates/";

//var imagePath = "~/My Documents/My Pictures/"; // Windows XP

//var imagePath = "~/Pictures/";                                // Windows 7

var imagePath = "E:/My Files/Pictures/";

Clean SC.jsx this forum make sure you download the last one in the thread Clean SL  Clean SL

JJMack

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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Thanks.

Can this work on groups as well?

I tried and it applied the same style to each layer in the group.

What i wanted was to apply the layer once, to the group.

Dan

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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

and where can i download Clean SL please?

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 Expert ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

The download link is in the thread I posted a link to. Go to the end of the thread and work backwards  the latest version download link should be near the end of the thread for the latest version.

JJMack

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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

LATEST

thanks i got it

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