Skip to main content
Inspiring
January 11, 2014
Question

Copy Layer's Parent Name to Clipboard

  • January 11, 2014
  • 1 reply
  • 1894 views

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...

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
January 11, 2014

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?

Inspiring
January 11, 2014

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

Inspiring
January 11, 2014

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?