Skip to main content
Known Participant
September 13, 2019
Answered

Copy Layer Name To Clipboard?

  • September 13, 2019
  • 2 replies
  • 5836 views

Hey folks,

 

i am looking for a script, which allows me to copy the name of my active layer to the clipboard.

 

Thank you for your help and best regrads,

 

S.

This topic has been closed for replies.
Correct answer Stephen Marsh

The following code should do the trick, it does exactly what you ask and nothing else:

 

 

 

// Copy Active Layer Name to Clipboard.jsx
#target photoshop 
var doc = activeDocument;
var aLayer = doc.activeLayer.name;
var d = new ActionDescriptor();  
d.putString(stringIDToTypeID("textData"), aLayer);  
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO); 

 

 

 

Based on:

https://community.adobe.com/t5/Photoshop/Copy-foreground-RGB-values-to-clipboard/td-p/10529244

 

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
September 13, 2019

The following code should do the trick, it does exactly what you ask and nothing else:

 

 

 

// Copy Active Layer Name to Clipboard.jsx
#target photoshop 
var doc = activeDocument;
var aLayer = doc.activeLayer.name;
var d = new ActionDescriptor();  
d.putString(stringIDToTypeID("textData"), aLayer);  
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO); 

 

 

 

Based on:

https://community.adobe.com/t5/Photoshop/Copy-foreground-RGB-values-to-clipboard/td-p/10529244

 

Known Participant
September 14, 2019

This script works awesome...

maybe you can help me out with my next problem. Now i want to rename my current group. The Name should be pasted from the clipboard.

 

thank you very much!

Known Participant
September 16, 2019

Here you go, I cheated and mostly used AM code as I did not have time to go through the JS Reference to see if there was standard code.

 

I was not sure if the original reference layer should be inside the group or not, so I left it outside the group. You mentioned the original layer colour being blue and the screenshot was in red so I went with red (this is easy enough to change).

 

 

 

 

 

 

// Set the Document
var doc = app.activeDocument;

// Set the Original Layer Name
var aLayer = doc.activeLayer.name;

// Load RGB channel selection
set();
function set() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();

	reference.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( c2t( "null" ), reference );
	reference2.putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "RGB" ));
	descriptor.putReference( s2t( "to" ), reference2 );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

// Add New Group
app.activeDocument.layerSets.add();

// Add Layer Mask from Selection
var idMk = charIDToTypeID( "Mk  " );
    var desc676 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
    var idChnl = charIDToTypeID( "Chnl" );
    desc676.putClass( idNw, idChnl );
    var idAt = charIDToTypeID( "At  " );
        var ref231 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref231.putEnumerated( idChnl, idChnl, idMsk );
    desc676.putReference( idAt, ref231 );
    var idUsng = charIDToTypeID( "Usng" );
    var idUsrM = charIDToTypeID( "UsrM" );
    var idRvlS = charIDToTypeID( "RvlS" );
    desc676.putEnumerated( idUsng, idUsrM, idRvlS );
executeAction( idMk, desc676, DialogModes.NO );

// Change the Group Name
app.activeDocument.activeLayer.name = aLayer;

// Add Curves Adjustment Layer
var idMk = charIDToTypeID( "Mk  " );
    var desc726 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref251 = new ActionReference();
        var idAdjL = charIDToTypeID( "AdjL" );
        ref251.putClass( idAdjL );
    desc726.putReference( idnull, ref251 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc727 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc728 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( "presetKind" );
            var idpresetKindType = stringIDToTypeID( "presetKindType" );
            var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
            desc728.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idCrvs = charIDToTypeID( "Crvs" );
        desc727.putObject( idType, idCrvs, desc728 );
    var idAdjL = charIDToTypeID( "AdjL" );
    desc726.putObject( idUsng, idAdjL, desc727 );
executeAction( idMk, desc726, DialogModes.NO );

// Add Hue/Saturation Adjustment Layer
var idMk = charIDToTypeID( "Mk  " );
    var desc755 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref263 = new ActionReference();
        var idAdjL = charIDToTypeID( "AdjL" );
        ref263.putClass( idAdjL );
    desc755.putReference( idnull, ref263 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc756 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc757 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( "presetKind" );
            var idpresetKindType = stringIDToTypeID( "presetKindType" );
            var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
            desc757.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
            var idClrz = charIDToTypeID( "Clrz" );
            desc757.putBoolean( idClrz, false );
        var idHStr = charIDToTypeID( "HStr" );
        desc756.putObject( idType, idHStr, desc757 );
    var idAdjL = charIDToTypeID( "AdjL" );
    desc755.putObject( idUsng, idAdjL, desc756 );
executeAction( idMk, desc755, DialogModes.NO );

// Select Backwards Layer x2
var idslct = charIDToTypeID( "slct" );
    var desc767 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref268 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref268.putEnumerated( idLyr, idOrdn, idBckw );
    desc767.putReference( idnull, ref268 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc767.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list78 = new ActionList();
        list78.putInteger( 107 );
    desc767.putList( idLyrI, list78 );
executeAction( idslct, desc767, DialogModes.NO );
// Select Backwards Layer Again
executeAction( idslct, desc767, DialogModes.NO );

/*
"None" = None
"Rd  " = Red
"Orng" = Orange
"Ylw " = Yellow
"Grn " = Green
"Bl  " = Blue
"Vlt " = Violet
"Gry " = Gray
Remember it appears twice: Rd & idRd, Gry & idGry etc.
*/
// Label the Layer Red
var idsetd = charIDToTypeID( "setd" );
    var desc565 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref160 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref160.putEnumerated( idLyr, idOrdn, idTrgt );
    desc565.putReference( idnull, ref160 );
    var idT = charIDToTypeID( "T   " );
        var desc566 = new ActionDescriptor();
        var idClr = charIDToTypeID( "Clr " );
        var idClr = charIDToTypeID( "Clr " );
        var idRd = charIDToTypeID( "Rd  " );
        desc566.putEnumerated( idClr, idClr, idRd );
    var idLyr = charIDToTypeID( "Lyr " );
    desc565.putObject( idT, idLyr, desc566 );
executeAction( idsetd, desc565, DialogModes.NO );

// Layer Visibility Off
doc.activeLayer.visible = false;

// Deselect layers  
// forums.adobe.com/message/5204655#5204655 - Michael L Hale  
app.runMenuItem(stringIDToTypeID('selectNoLayers'));

 

 

 

 

 

 

 

 

 

 


your script is awesome! Thank you very much for your help! I do not want to be annoying, but can you show me the line where the "layer" is moved outside the group and if it´s possible to set the blendmode of the curvelayer to luminosity?

 

one more time. Thank you very very much!!!

smithcgl9043167
Inspiring
September 13, 2019
////// Run over matrix layer
var theLayer = activeDocument.activeLayer;
var theParent = theLayer.parent;
if (theParent != activeDocument) {var theString = theParent.name+"-"+theLayer.name}
else {var theString = theLayer.name};

changeLayer(); ////// Choose target layer
function changeLayer(){
	var des = new ActionDescriptor();
	var list = new ActionList();
	var ref = new ActionReference();
	ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ));
	des.putReference( charIDToTypeID( "null" ), ref );
	list.putInteger( 3 );
	des.putList( charIDToTypeID( "LyrI" ), list );
	executeAction( charIDToTypeID( "slct" ), des, DialogModes.NO );
}

////////// Paste Name:
app.activeDocument.activeLayer.name = theString;