Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
////// 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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have several Black and white layers which i need as masks. Now i want an Action including following steps: 1.copy layername to clipboard 2. change color Layer to blue 3. create new group with the same Name as the Layer (Layer is a child of the Group) 4.select the layer and copy all pixels (its not possible to copy a single channel, because they might be different) 5.select group, add Mask and paste in the pixels 6. again select the layer and add following adjustment layers (curve and hue/sat)
end of Action
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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'));
Copy link to clipboard
Copied
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!!!
Copy link to clipboard
Copied
The group was created independently, so the layer was not moved out of the group as the group was created empty. Do you require the original target/source layer to be inside the layer group/set (I was not sure from the original screenshot)?
To set the curve layer blend mode, the following two lines of code can be added after the curve code block, before the hue/saturation code block:
// Set the Curves Adjustment Layer to Luminosity Blend Mode
doc.activeLayer.blendMode = BlendMode.LUMINOSITY;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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'));
Copy link to clipboard
Copied
Hey Stephen,
thanks a lot for the script. It saves me a ton of time.
I am looking for a solution of a new problem...
I have an action, which is called TEMP.
Now I would like to create a new set of actions which has the same name as my file.
I have following script for copying my filename to the clipboard.
#target photoshop
var d = new ActionDescriptor();
d.putString(stringIDToTypeID("textData"), File.decode(arguments[0].getPath(stringIDToTypeID("in")).name));
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO);
Can you help me, to create a set of actions with the name?
it would be awesome, everything else i should be able to realize with an action.
thanks once again and best regards,
Sebastian
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied