Skip to main content
Known Participant
September 13, 2019
Answered

Copy Layer Name To Clipboard?

  • September 13, 2019
  • 2 replies
  • 5782 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!

Stephen Marsh
Community Expert
Community Expert
September 17, 2019

IHey Stephen, I would require the source layer to be inside the layer group. Unfortunately it´s difficult to see on the screenshot, but the layer is a child of the group. sorry, my fault. I´ve should make it clear, in my first description.


Not a problem, I’ll update this post with the new code shortly...

 

 

 

 

 

 

#target photoshop

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

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

// Make Group from Selected Layer
var idMk = charIDToTypeID( "Mk  " );
    var desc1255 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref506 = new ActionReference();
        var idlayerSection = stringIDToTypeID( "layerSection" );
        ref506.putClass( idlayerSection );
    desc1255.putReference( idnull, ref506 );
    var idFrom = charIDToTypeID( "From" );
        var ref507 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref507.putEnumerated( idLyr, idOrdn, idTrgt );
    desc1255.putReference( idFrom, ref507 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc1256 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc1256.putString( idNm, """Temp_Group""" );
    var idlayerSection = stringIDToTypeID( "layerSection" );
    desc1255.putObject( idUsng, idlayerSection, desc1256 );
    var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
    desc1255.putInteger( idlayerSectionStart, 268 );
    var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
    desc1255.putInteger( idlayerSectionEnd, 269 );
    var idNm = charIDToTypeID( "Nm  " );
    desc1255.putString( idNm, """Temp_Group""" );
executeAction( idMk, desc1255, DialogModes.NO );

// Select Backwards Layer
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 );

// 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 );

// Set the Curves Adjustment Layer to Luminosity Blend Mode
doc.activeLayer.blendMode = BlendMode.LUMINOSITY;

// 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
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 );

// 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 );
}

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

/* Park this code block and use getByName instead...
// Select the Forward Layer
select(false);
function select(makeVisible) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

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

	var descriptor = new ActionDescriptor();
	var list = new ActionList();
	var reference = new ActionReference();

	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "forwardEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor.putBoolean( s2t( "makeVisible" ), makeVisible );
	list.putInteger( 250 );
	descriptor.putList( s2t( "layerID" ), list );
    // Run it 3 times!
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );    
}
*/

// Select the Group By Name
// stackoverflow.com/questions/18436995/find-layergroup-of-a-specific-layer-in-photoshop-with-javascript
app.activeDocument.activeLayer = app.activeDocument.layerSets.getByName("Temp_Group");

// 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;

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

 

 

 

 

 

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;