Skip to main content
Participating Frequently
January 23, 2024
Open for Voting

Is there a way to swap fill and stroke color for shapes in Photoshop?

In Ilustrator and InDesgin it's super easy: there is a button in the interface (swap fill and stroke) and a keyboard shortcut (Shift X), in Photoshop: nothing.

It would be great to be able to quickly swich the colors around because the most common 2 things I use for shapes are:

- a line (where i need a fill) 

- a rectangular frame (where i need a stroke)

so when i need to switch between a line and a frame i keep having to fiddle in the top mini-buttons interface: select the color from the recent swatches for a stroke, and selecting "none" for the fill >> that's 6 clicks!! It takes me out of my flow, is there a way to do this faster like in Illustrator/InDesign? And if not: how do I suggest this improvement to the developers?

8 replies

c.pfaffenbichler
Community Expert
Community Expert
June 15, 2024

Updated to handle »No Color«. 

 

// switch shape layer’s fill and stroke colors; 
// 2024, use at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
try {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var theFillColor = layerDesc.getList(stringIDToTypeID("adjustment")).getObjectValue(0).getObjectValue(stringIDToTypeID("color"));
var theStroke = layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo"));
var fillEnabled = theStroke.getBoolean(stringIDToTypeID("fillEnabled"));
var strokeEnabled = theStroke.getBoolean(stringIDToTypeID("strokeEnabled"));
var theStrokeColor = theStroke.getObjectValue(stringIDToTypeID("strokeStyleContent")).getObjectValue(stringIDToTypeID("color"));
////////////////////////////////////
if (strokeEnabled == true) {
var desc19 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc19.putReference( stringIDToTypeID( "null" ), ref3 );
var desc20 = new ActionDescriptor();
var idfillContents = stringIDToTypeID( "fillContents" );
var desc21 = new ActionDescriptor();
desc21.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), theStrokeColor/*desc22*/ );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc20.putObject( idfillContents, idsolidColorLayer, desc21 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc23 = new ActionDescriptor();
desc23.putInteger( stringIDToTypeID( "strokeStyleVersion" ), theStroke.getInteger(stringIDToTypeID( "strokeStyleVersion" )) );
desc23.putBoolean( stringIDToTypeID( "fillEnabled" ), true );
desc20.putObject( idstrokeStyle, idstrokeStyle, desc23 );
desc19.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc20 );
executeAction( stringIDToTypeID( "set" ), desc19, DialogModes.NO );
} else {
var desc12 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc12.putReference( stringIDToTypeID( "null" ), ref3 );
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putInteger( stringIDToTypeID( "strokeStyleVersion" ), 2 );
desc14.putBoolean( stringIDToTypeID( "fillEnabled" ), false );
desc13.putObject( stringIDToTypeID( "strokeStyle" ), stringIDToTypeID( "strokeStyle" ), desc14 );
desc12.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "shapeStyle" ), desc13 );
executeAction( stringIDToTypeID( "set" ), desc12, DialogModes.NO );
};
////////////////////////////////////
if (fillEnabled == true) {
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();
        desc11.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), theFillColor );
    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 );
} else {
// =======================================================
    var desc10 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated( stringIDToTypeID( "contentLayer" ), stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
    desc10.putReference( stringIDToTypeID( "null" ), ref1 );
        var desc11 = new ActionDescriptor();
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            var desc12 = new ActionDescriptor();
            desc12.putInteger( stringIDToTypeID( "strokeStyleVersion" ), 2 );
            desc12.putBoolean( stringIDToTypeID( "strokeEnabled" ), false );
        desc11.putObject( idstrokeStyle, idstrokeStyle, desc12 );
    var idshapeStyle = stringIDToTypeID( "shapeStyle" );
    desc10.putObject( stringIDToTypeID( "to" ), idshapeStyle, desc11 );
executeAction( stringIDToTypeID( "set" ), desc10, DialogModes.NO );
};
} catch (e) {alert ("no")}
};

 

Translate
c.pfaffenbichler
Community Expert
Community Expert
June 13, 2024

// 2024, use at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var theFillColor = layerDesc.getList(stringIDToTypeID("adjustment")).getObjectValue(0).getObjectValue(stringIDToTypeID("color"));
var theStroke = layerDesc.getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo"));
var theStrokeColor = theStroke.getObjectValue(stringIDToTypeID("strokeStyleContent")).getObjectValue(stringIDToTypeID("color"));
////////////////////////////////////
var desc4 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated ( stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
desc4.putReference( charIDToTypeID( "null" ), ref1 );
var desc5 = new ActionDescriptor();
desc5.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), theStrokeColor );
desc5.putObject( charIDToTypeID("Clr "), stringIDToTypeID("RGBColorClass"), theStrokeColor );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc4.putObject( charIDToTypeID("T   "), idsolidColorLayer, desc5 );
executeAction( charIDToTypeID("setd"), desc4, DialogModes.NO );
////////////////////////////////////
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();
        desc11.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), theFillColor );
    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 );
};
Translate
c.pfaffenbichler
Community Expert
Community Expert
June 13, 2024

That sounds like it’s scriptable. 

Translate
Nancy OShea
Community Expert
Community Expert
June 12, 2024

If you say so...

 

Translate
Nancy O'Shea— Product User & Community Expert
Known Participant
June 11, 2024

NO. it's 6

Translate
Nancy OShea
Community Expert
Community Expert
June 10, 2024

It takes 2 clicks -- one for stroke, one for fill.

 

Translate
Nancy O'Shea— Product User & Community Expert
Stephen Marsh
Community Expert
Community Expert
June 10, 2024
quote

how do I suggest this improvement to the developers?


By @RV999

 

You have by marking this topic as an "idea" rather than as a bug or discussion.

Translate
Known Participant
June 10, 2024

Every time I use Photoshop I wish for this feature
Six clicks is crazy

Translate