Copy link to clipboard
Copied
Hi
I have a script which copies the active layer's name to the clipboard (thanks to the users in this forum):
app.system( "echo " + activeDocument.activeLayer.name + " | CLIP");
...Is there a way to copy the active layer's Parent name to the clipboard instead?
or to take it a step further, copy the Parent name first, then copy the active layer name?
For example, it would copy to the clipboard: "Group 1- Layer 1"
(meaning that there is a group entitled "Group 1", and inside that group is 'Layer 1' (which, by the way, would also be the active layer))
Or if that's too complicated, then just to simply copy the parent name.
Hope this makes sense...
Copy link to clipboard
Copied
Something like this maybe
var theLayer = activeDocument.activeLayer;
var theParent = theLayer.parent;
if (theParent != activeDocument) {var theString = theParent.name+"-"+theLayer.name}
else {var theString = theLayer.name};
alert(theString);
app.system( "echo " + theString + " | CLIP");
But why anyway?
Copy link to clipboard
Copied
thanks, this is perfect. I'll explain why:
First, I select the Move tool and turn on 'auto select', which allows me to just left-click anywhere inside my photoshop document and it will automatically select the layer under the cursor (standard procedure).
I've managed to assemble an AutoHotKey script which will wait for the left-click to occur, and when it does, it runs your .jsx script which copies the parent layer name and also the active layer name to the clipboard. The AutoHotKey script then displays the clipboard information as a tooltip.
So basically -
I use the move(auto-select) tool to select my layers in the photoshop document, and each time I left click in the document window, a tooltip appears, showing me what layer I switched to and is now active. This is especially useful when working in fullscreen mode and you can't see the layers panel.
So thanks again for this, it's so useful
Copy link to clipboard
Copied
which leads me to one last question -
I'm trying to assemble a small script which make the group's parent layer active. Here's what I've done:
var doc = app.activeDocument;
var theParent = theLayer.parent;
doc.activeLayer = theParent;
But it's returning an Error2 code. I've tinkered endlessley with this to no avail. Is there a way to select the Parent Layer of the group?
Copy link to clipboard
Copied
You forgot to define »theLayer«.
Inserting
var theLayer = activeDocument.activeLayer;
should work.
Copy link to clipboard
Copied
Thanks, that works perfectly now. Combining AutoHotKey with Photoshop does wonders... I must have a few hundred scripts that I've programmed this past year to really improve my workflow is PS. Unfortunately I'm not quite as knowledgable with .jsx scripting but I'll get better so long as I keep reading the forums here
Now, using your script, I'm able to use the 'Auto-select move' tool and whener I click on my document, it shows me a tooltip of the layer I just selected. Then I run your script and it selects the parent layer of the group (if it's a group that is currently selected), enabling to move the entire group anywhere within the image. This really helps to quickly and accurately select layers when I'm getting up to 100 or more.
Come to think of it, with a little more thought, I think I might be able to entirely program a brand new, custom layers panel and design my own interface for it - meaning that I wouldn't need to use the stock layers panel that Photoshop uses. It's an incredible thought - and it would be achieved by using all your scripts on this page and others in the forums. I'll keep everyone posted if it's something I can whip up. The reason for this would be that I can make the panel any size I wish, any color, any location on the screen, I can program my own 'auto-hide/auto-show' feature for it, and even include custom sounds when selecting certain layers, and so on. I've already designed my own tool presets panel and I don't even use the stock one any more (thanks to .jsx scripting, AutoHotKey and another 3rd party app named PowerPro). So thanks again
Copy link to clipboard
Copied
I am so, so close here with this script... this one is trying to copy all layer names to the clipboard, but again it's returning an 'undefined is not an object' error. After 2 hours I've spent my brainpower trying to figure out what the problem is:
var docRef = app.activeDocument;
for( var i = 0 ; i < docRef.layers.length ; i++)
app.system( "echo " + docRef.Layers.name + " | CLIP");
Copy link to clipboard
Copied
Layers are filial to the Groups (LayerSets) that contain them, so activeDocument.layers will not include Layers in Groups.
Also »layers« is not capitalized here.
var docRef = app.activeDocument;
var theArray = new Array;
for( var i = 0 ; i < docRef.layers.length ; i++) {
theArray.push(docRef.layers.name)
};
app.system( "echo " + theArray.join("\n") + " | CLIP");
Copy link to clipboard
Copied
thanks, c - isn't working just yet though. Doesn't seem to be copying anything to the clipboard.. I tried changing 'join' to 'push' and it seems to then copy the total number of layers into the clipbaord though.
Copy link to clipboard
Copied
so it looks like I've managed to get it working, using a few different methods. First, I run the following script to copy all the layer names and then the script exports them to a .txt file, not to the clipboard:
var docRef = app.activeDocument;
var fdOutput = "/c/myfolder"
var flOutput = new File( fdOutput + "/ListOfAllLayerNames.txt" );
flOutput.open("w");
for( var i = 0 ; i < docRef.layers.length ; i++)
{
flOutput.write("" + docRef.layers.name);
if ( docRef.layers.kind == "LayerKind.TEXT")
{
flOutput.write(" -> Text : '" + docRef.layers.textItem.contents + "'" );
}
flOutput.write("\n");
}
{
flOutput.write("\n");
}
flOutput.close();
I discovered the above code on the net, and spent a little bit of time stripping it down to what I needed (took a lot of studying, since I know very little about javascripting, but I managed to get it this far)
Then, I open up the exported file in notepad, and it shows all the layer names in the text document. Then just hit ^a to select all, then ^c to copy the contents and voila, all layer names are now in the clipboard. As mentioned before, I use AutoHotKey to automate the entire process, so simply pressing one key on the keyboard will carry out the entire process above. Thanks again for the help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now