Skip to main content
Participant
July 22, 2023
Answered

Script for changing shape stroke color

  • July 22, 2023
  • 2 replies
  • 385 views

Been googling for couple days but no such script exist on the internet i suppose.

How can I change selected activeLayer shape's stroke color with a .jsx script ?

This topic has been closed for replies.
Correct answer c.pfaffenbichler
// 2023, use at your own risk;
changeShapeLayerStrokeColor ([Math.random()*255,Math.random()*255,Math.random()*255]);
function changeShapeLayerStrokeColor (theRGBColor) {
try {
    var desc8 = new ActionDescriptor();
        var ref4 = new ActionReference();
        ref4.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc8.putReference( stringIDToTypeID( "null" ), ref4 );
        var desc9 = new ActionDescriptor();
            var desc10 = new ActionDescriptor();
                var desc11 = new ActionDescriptor();
                    var desc12 = new ActionDescriptor();
                    desc12.putDouble( stringIDToTypeID( "red" ), theRGBColor[0] );
                    desc12.putDouble( stringIDToTypeID( "grain" ), theRGBColor[1] );
                    desc12.putDouble( stringIDToTypeID( "blue" ), theRGBColor[2] );
                desc11.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), desc12 );
            desc10.putObject( stringIDToTypeID( "strokeStyleContent" ), stringIDToTypeID( "solidColorLayer" ), desc11 );
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc10.putInteger( idstrokeStyleVersion, 2 );
            desc10.putBoolean( stringIDToTypeID( "strokeEnabled" ), true );
        desc9.putObject( stringIDToTypeID( "strokeStyle" ), stringIDToTypeID( "strokeStyle" ), desc10 );
    desc8.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc9 );
executeAction( stringIDToTypeID( "set" ), desc8, DialogModes.NO );
} catch (e) {}
};

2 replies

Stephen Marsh
Community Expert
Community Expert
July 22, 2023
c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
July 22, 2023
// 2023, use at your own risk;
changeShapeLayerStrokeColor ([Math.random()*255,Math.random()*255,Math.random()*255]);
function changeShapeLayerStrokeColor (theRGBColor) {
try {
    var desc8 = new ActionDescriptor();
        var ref4 = new ActionReference();
        ref4.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc8.putReference( stringIDToTypeID( "null" ), ref4 );
        var desc9 = new ActionDescriptor();
            var desc10 = new ActionDescriptor();
                var desc11 = new ActionDescriptor();
                    var desc12 = new ActionDescriptor();
                    desc12.putDouble( stringIDToTypeID( "red" ), theRGBColor[0] );
                    desc12.putDouble( stringIDToTypeID( "grain" ), theRGBColor[1] );
                    desc12.putDouble( stringIDToTypeID( "blue" ), theRGBColor[2] );
                desc11.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), desc12 );
            desc10.putObject( stringIDToTypeID( "strokeStyleContent" ), stringIDToTypeID( "solidColorLayer" ), desc11 );
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc10.putInteger( idstrokeStyleVersion, 2 );
            desc10.putBoolean( stringIDToTypeID( "strokeEnabled" ), true );
        desc9.putObject( stringIDToTypeID( "strokeStyle" ), stringIDToTypeID( "strokeStyle" ), desc10 );
    desc8.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc9 );
executeAction( stringIDToTypeID( "set" ), desc8, DialogModes.NO );
} catch (e) {}
};