Skip to main content
Tomas Sinkunas
Brainiac
September 7, 2017
Question

Clean SL

  • September 7, 2017
  • 11 replies
  • 23157 views

Hello gang!

I just wanted to share with you my small utility tool for Photoshop called Clean SL that cleans ScriptingListenerJS.log file to make it more readable.

Recently watched Davide_Barranca​'s Adobe Photoshop HTML Panels Development course  and realised how painful it is to work with Action Manager's code and how unreadable it is right off the box. I know there are quite a few other tools that cleans log file, however it doesn't hurt to have an option to choose.

Interested? Grab it here: rendertom / Clean SL / source / — Bitbucket

Script performs multiple actions such as cleaning-up variable names and hoisting them to the top, wraps code block into function, converts charID to string ID for better readability and such. Resulting code is clean and maintains better readability.

Features:

  • Load entire ScriptingListenerJS.log content
  • Load only last entry in ScriptingListenerJS.log
  • Enter ScriptingListenerJS code manually

Options:

  • Hoist variable declaration to the top
  • Consolidate variables
  • Give descriptive variable names
  • Convert charID to stringID for better readability
  • Replace stringIDToTypeID() to s2t() function
  • Wrap to function block.

Example:

From this:

var idHStr = charIDToTypeID( "HStr" );

    var desc21 = new ActionDescriptor();

    var idpresetKind = stringIDToTypeID( "presetKind" );

    var idpresetKindType = stringIDToTypeID( "presetKindType" );

    var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );

    desc21.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );

    var idClrz = charIDToTypeID( "Clrz" );

    desc21.putBoolean( idClrz, false );

    var idAdjs = charIDToTypeID( "Adjs" );

        var list1 = new ActionList();

            var desc22 = new ActionDescriptor();

            var idH = charIDToTypeID( "H   " );

            desc22.putInteger( idH, 39 );

            var idStrt = charIDToTypeID( "Strt" );

            desc22.putInteger( idStrt, 23 );

            var idLght = charIDToTypeID( "Lght" );

            desc22.putInteger( idLght, -27 );

        var idHsttwo = charIDToTypeID( "Hst2" );

        list1.putObject( idHsttwo, desc22 );

    desc21.putList( idAdjs, list1 );

executeAction( idHStr, desc21, DialogModes.NO );

to this:

hueSaturation();

function hueSaturation() {

    var s2t = function (s) {

        return app.stringIDToTypeID(s);

    };

    var descriptor = new ActionDescriptor();

    var list = new ActionList();

    var descriptor2 = new ActionDescriptor();

    descriptor.putEnumerated( s2t( "presetKind" ), s2t( "presetKindType" ), s2t( "presetKindCustom" ));

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

    descriptor2.putInteger( s2t( "hue" ), 39 );

    descriptor2.putInteger( s2t( "saturation" ), 23 );

    descriptor2.putInteger( s2t( "lightness" ), -27 );

    list.putObject( s2t( "hueSatAdjustmentV2" ), descriptor2 );

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

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

}

Installation

Clone or download repository and place Clean SJ.jsx script to Photoshop’s Scripts folder:

Adobe Photoshop CC 20XX -> Presets -> Scripts -> Clean JS.jsx

Restart Photoshop to access Clean JS script from File -> Scripts

------------------------------------------------

Since I am rather new to Photoshop Scripting, I might have missed something of my code brakes. So if you find any bugs or issues, please do not hesitate to let me know so I could fix it.

So, happy cleaning everybody!

This topic has been closed for replies.

11 replies

New Participant
June 8, 2022

It's a splendid tool, and something that would definitely benefit from; making better sense of "code soup!"

 

I've successfully installed the ScriptingListener plugin, as well as your Clean SL script on my machine, and am able to bring up the window. 

 

The Problem is, I can't seem to Load the Full log, or load the last log entry either.  (blank screen.)  I double-checked my desktop, and indeed the ScriptingListenerJS.log is in there.  I'm running Clean ScriptingListenerJS.log v1.4 on Photoshop v 23.3.2 (newest version,) on Windows 10.  Any Suggestions? Thanks.  

 

 

Kukurykus
Brainiac
March 17, 2018

I was during my nine months inactivity on this forum when another tool to convert SL code was made, after ten months earlier I wrote mine that I shared as well with this community. Later in that time I also found xbytor2 scripted his one too.

Now I've read all posts in this theard do find differences in our produtcs and fortunatelly see that all I did for myself is sufficient. The only two things I did not fix in my code (I found after very last change) were default triple quotes to be appeared as single ones, and handling XML code.

First thing I considered not needed after all, however I found when there is no content in '''''' then all next lines (starting from opening quotes) to end of ExtendScript ToolKit gets quoted appearance. What is funny all code still works with no problem. As it occurs extremaly rare, and it needs only little manual change of one triple quote set to single one I let it remain in original shape.

The second thing I considered as unnecessary for my work to fix and probably more rare than first one is XML written to SL. You can create it by using Lens Correction from Filters in Photoshop. I just downloaded your Clean SL script to see did you solve this problem, but I see that not. If you find you want that XML bug be fixed, your code will be nothing than perfect

Regarding me I am not going to update my code. I created dedicated topic on this fourm in December 2016 where I gave users chance me to change anything they want in my script. But only Jarda Bereza and JavierAroche had some wishes / advices. I changed then some things for them what I wrote in a topic the code was posted in. Seeing no more requests I considered code fits people expectations and as far as it is also good for me I did not make more changes.

As to single convertion of a code, that how that looks like comparing our outputs it seems there are slight differences, one can like more or less. I had no reports mine failed ever (at least from myself using it often), and yours too, so we can say to ourselves good job

JJMack
Community Expert
September 13, 2017

I think most use Action manager Code to make functions that have parameters.  Your tool make it easier to add the parameters for one can actually read your cleaned code.  Adding an option to do that would be good. We could use it either way.   Text is a beast.  I feel I never be able to script text well.

JJMack
Tomas Sinkunas
Brainiac
September 13, 2017

Started implementing Extract Parameters function. It's in dev branch. In case someone wants to test it - find it here:

rendertom / Clean SL / source / — Bitbucket

Cheers.

JJMack
Community Expert
September 13, 2017

First thing I tried failed.  I I download was the CleanSL script.  It faile with or wothout checking the nes option.  All I di in Photoshop was set a color sampler in CC 2017.  Yos script looped twice throwing the script error and genedated not actual cleaned code. Line 386 the function line

function incrementKeys(string) {

var keyName = string;

keyName = validateName(keyName);

return increment(keyName, storedKeys);

}

here is the scriptlistener log

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

var idDlt = charIDToTypeID( "Dlt " );

    var desc112 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref17 = new ActionReference();

        var idClSm = charIDToTypeID( "ClSm" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idAl = charIDToTypeID( "Al  " );

        ref17.putEnumerated( idClSm, idOrdn, idAl );

    desc112.putReference( idnull, ref17 );

executeAction( idDlt, desc112, DialogModes.NO );

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

var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );

    var desc113 = new ActionDescriptor();

    var idLvl = charIDToTypeID( "Lvl " );

    desc113.putInteger( idLvl, 1 );

    var idStte = charIDToTypeID( "Stte" );

    var idStte = charIDToTypeID( "Stte" );

    var identer = stringIDToTypeID( "enter" );

    desc113.putEnumerated( idStte, idStte, identer );

    var idTool = charIDToTypeID( "Tool" );

        var desc114 = new ActionDescriptor();

        var idIdnt = charIDToTypeID( "Idnt" );

        desc114.putString( idIdnt, """cols""" );

        var idTtl = charIDToTypeID( "Ttl " );

        desc114.putString( idTtl, """Color Sampler Tool""" );

    var idTool = charIDToTypeID( "Tool" );

    desc113.putObject( idTool, idTool, desc114 );

    var idKnd = charIDToTypeID( "Knd " );

    var idKnd = charIDToTypeID( "Knd " );

    var idmouse = stringIDToTypeID( "mouse" );

    desc113.putEnumerated( idKnd, idKnd, idmouse );

    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

    desc113.putBoolean( idkcanDispatchWhileModal, true );

executeAction( idtoolModalStateChanged, desc113, DialogModes.NO );

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

var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );

    var desc115 = new ActionDescriptor();

    var idLvl = charIDToTypeID( "Lvl " );

    desc115.putInteger( idLvl, 0 );

    var idStte = charIDToTypeID( "Stte" );

    var idStte = charIDToTypeID( "Stte" );

    var idexit = stringIDToTypeID( "exit" );

    desc115.putEnumerated( idStte, idStte, idexit );

    var idTool = charIDToTypeID( "Tool" );

        var desc116 = new ActionDescriptor();

        var idIdnt = charIDToTypeID( "Idnt" );

        desc116.putString( idIdnt, """cols""" );

        var idTtl = charIDToTypeID( "Ttl " );

        desc116.putString( idTtl, """Color Sampler Tool""" );

    var idTool = charIDToTypeID( "Tool" );

    desc115.putObject( idTool, idTool, desc116 );

    var idKnd = charIDToTypeID( "Knd " );

    var idKnd = charIDToTypeID( "Knd " );

    var idmouse = stringIDToTypeID( "mouse" );

    desc115.putEnumerated( idKnd, idKnd, idmouse );

    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

    desc115.putBoolean( idkcanDispatchWhileModal, true );

executeAction( idtoolModalStateChanged, desc115, DialogModes.NO );

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

var idMk = charIDToTypeID( "Mk  " );

    var desc117 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref18 = new ActionReference();

        var idClSm = charIDToTypeID( "ClSm" );

        ref18.putClass( idClSm );

    desc117.putReference( idnull, ref18 );

    var idPstn = charIDToTypeID( "Pstn" );

        var desc118 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc118.putUnitDouble( idHrzn, idPxl, 316.500000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc118.putUnitDouble( idVrtc, idPxl, 301.500000 );

    var idPnt = charIDToTypeID( "Pnt " );

    desc117.putObject( idPstn, idPnt, desc118 );

executeAction( idMk, desc117, DialogModes.NO );

JJMack
Tomas Sinkunas
Brainiac
September 13, 2017

Gang, what about yet another option in Clean SL to extract method parameters?

It would really work great with small AM codes, like opening documents, changing Hue/Sat, transform, maybe something else, as those use few parameters. However it would actually blow up with textlayers, as there would be >80 params.

But still, trying to explore the possibility.

Before:

transform();

function transform() { ... }

After:

transform(0, 0, 45);

function transform(horizontal, vertical, angle) { ... }

Some examples:

open2(new File( "/Users/rendertom/Desktop/Image.png" ));

function open2(null4) {

    var descriptor = new ActionDescriptor();

    descriptor.putPath( charIDToTypeID( "null" ), null4 );

    descriptor.putInteger( stringIDToTypeID( "documentID" ), 210 );

    executeAction( stringIDToTypeID( "open" ), descriptor, DialogModes.NO );

}

hueSaturation(false, 20, 33, 52);

function hueSaturation(colorize, hue, Strt, lightness) {

    var descriptor = new ActionDescriptor();

    var descriptor2 = new ActionDescriptor();

    var list = new ActionList();

    descriptor.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindCustom" ));

    descriptor.putBoolean( stringIDToTypeID( "colorize" ), colorize );

    descriptor2.putInteger( stringIDToTypeID( "hue" ), hue );

    descriptor2.putInteger( charIDToTypeID( "Strt" ), Strt );

    descriptor2.putInteger( stringIDToTypeID( "lightness" ), lightness );

    list.putObject( stringIDToTypeID( "hueSatAdjustmentV2" ), descriptor2 );

    descriptor.putList( stringIDToTypeID( "adjustment" ), list );

    executeAction( stringIDToTypeID( "hueSaturation" ), descriptor, DialogModes.NO );

}

transform(-24, 7.5, 54.658385, 55);

function transform(horizontal, vertical, width, height) {

    var descriptor = new ActionDescriptor();

    var descriptor2 = new ActionDescriptor();

    var reference = new ActionReference();

    reference.putEnumerated( stringIDToTypeID( "layer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ));

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

    descriptor.putEnumerated( stringIDToTypeID( "freeTransformCenterState" ), stringIDToTypeID( "quadCenterState" ), stringIDToTypeID( "QCSAverage" ));

    descriptor2.putUnitDouble( stringIDToTypeID( "horizontal" ), stringIDToTypeID( "pixelsUnit" ), horizontal );

    descriptor2.putUnitDouble( stringIDToTypeID( "vertical" ), stringIDToTypeID( "pixelsUnit" ), vertical );

    descriptor.putObject( stringIDToTypeID( "offset" ), stringIDToTypeID( "offset" ), descriptor2 );

    descriptor.putUnitDouble( stringIDToTypeID( "width" ), stringIDToTypeID( "percentUnit" ), width );

    descriptor.putUnitDouble( stringIDToTypeID( "height" ), stringIDToTypeID( "percentUnit" ), height );

    descriptor.putEnumerated( charIDToTypeID( "Intr" ), stringIDToTypeID( "interpolationType" ), stringIDToTypeID( "bicubic" ));

    executeAction( stringIDToTypeID( "transform" ), descriptor, DialogModes.NO );

}

Tomas Sinkunas
Brainiac
September 11, 2017

Much love to everyone contributing, especially JJMack for testing it. Love you guys!

 

Clean SL v1.3 is online: Please remove old Clean SL Settings.txt file before using this update.

  • Renames Descriptive variable name to Rename constructors
  • Renames Shorten stringIDToTypeID to Shorten method names
  • Exposes predefined object with variables for you guys to change in code:
    •    junkArray: in case I am removing something important, feel free to edit this.
    •    constructorNames: feel free to change how you name your constructors. Davide_Barranca going to love this!
    •    shortMethodNames : if you don't like name s2t() or c2t() feel free to edit this.
    •    printToESTK: want to print clean code to ESTK console? Sure thing SuperMerlin
    •    removeJunkOnFullLogRead: as you requested JJMack
    •    closeAfterSaving : done! geppettol66959005
  • Removes duplicate variable declarations and sorts them alphabetically when hoisting
  • Shorten method names shortens both charIDToTypeID() and stringIDToTypeID()
  • Skips converting charIDtoStringID() if CharID has conflicting StringID values - thanks xbytor2 and Davide_Barranca for bringing this to my attention.
  • Parses variable declarations to check if same variable has different values - JJMack you had issues with this in your extra-big log file you sent me earlier.

 

Enjoy!

Davide_Barranca12040269
Community Expert
September 11, 2017

Great rounds of updates, thank you, Tomas!

Davide Barranca - PS developer and authorwww.ps-scripting.com
Stephen Marsh
Community Expert
September 11, 2017

What have I done wrong? Is there a dependency on this JSON2.JS file? Latest CC17…

Is this the one?

json2.js · GitHub

JJMack
Community Expert
September 10, 2017

The make that fails is a make text layer so any make text will fail. So disabled convert charID to stringID option will fix the problem for me anyway.  Action manager code recorded by scriptlisten is nasty to look at.  Russ and Davide know scripting I just hack at it.

JJMack
AlyLohStress
New Participant
September 10, 2017

WAW that's great of you! Thank you so much !!!

Known Participant
November 27, 2019

Heya! 

 

Came across this but it does not seem to be working for Photoshop 2020? Will this be updated you think? I get a lot of errors even with simple things unless I remove the codes.

JJMack
Community Expert
September 8, 2017

Tomas a cpiple of questions.

First when I open your Clean SL script there is some code in the left side panel.  What is that code where does it come from its not in my scriptlistemer log file.  I do not even use artboards but the code I see seems to be for creating an artboard.

Second the left side panel source code is editable and that is a grate feature.  However the next panel the clean code is not editable. It the any chance the you could make that panel editable like the source panel.  I would like to try to add parameters to your functions set their values  and add them into the function you made and then be able to have Clean SL evaluate the changed code.

JJMack
Tomas Sinkunas
Brainiac
September 8, 2017

JJMack​ The starting code you see once you launch Clean SL is just a demo code. Clean SL doesn't read ScriptingListener.log file upon loading. I decided to leave that test code in there so users don't get empty screen when launching Clean SL. So feel free to ignore and delete it.

I might implement options in the future to "remember source code / clean code after panel closes", so it would load last code you had in those edittext boxes.

Regarding not being able to edit clean code's edittext - well, you should be able to edit both of them. Unless there's some bug on Windows that prevents from entering text manually.

I tested on Mac CS6, CC2014 & CC2017 and I am able to edit those textboxes manually.

Geppetto Luis
Brainiac
September 9, 2017

That's a great job

thanks for sharing

I suggest inserting this output change

if (pathToFile) {

saveFile (pathToFile, "jsx", etOutputText.text);

win.close ();

JJMack
Community Expert
September 8, 2017

Right now I'm looking to see if there is a newer version of scriptlistener for CC 2017.  I do not normally use CC 2017.  I use CC 2014.   Your Clean SL works better in CS6 and CC 2014.  For the Scriptlistener does not record the  junk it records in CC 2017.  I have not tested CC 2015 and CC 2015.5. I do not use them. I do have them installed.

The onle plugin I see on Adobe site is dated 2012

JJMack
Inspiring
September 8, 2017

One thing you have to be aware of is that string ids and char ids are not a one-to-one mapping.

For instance, "Strt" maps to "Saturation" and "Start".