Copy link to clipboard
Copied
Hi, help me write a script to create a text layer, where text = name of the active layer
Copy link to clipboard
Copied
#target photoshop-130.064
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// getting the name;
var docName = myDocument.name;
var theLayerName = myDocument.activeLayer.name;
// make the layer;
var myLayerRef = myDocument.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = theLayerName;
var myTextRef = myLayerRef.textItem;
myTextRef.size = 14;
myTextRef.font = "Courier";
myTextRef.justification = Justification.RIGHT;
//Set text colour in RGB values
var newColor = new SolidColor();
newColor.rgb.red = 0;
newColor.rgb.green = 0;
newColor.rgb.blue = 0;
myTextRef.color = newColor;
// Set the position of the text - percentages from left first, then from top.
myTextRef.position = new Array( myDocument.width - 85, myDocument.height - 85);
myLayerRef.blendMode = BlendMode.NORMAL;
myLayerRef.opacity = 100;
myTextRef.contents = theLayerName;
app.preferences.rulerUnits = originalUnits;
};
//that’s it; thanks to xbytors;
Copy link to clipboard
Copied
My hack:
#target photoshop
// Current layer name as text layer
var myDoc = app.activeDocument;
var myRulers = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS;
var myLayerName = myDoc.activeLayer.name;
var myLayerText = myDoc.artLayers.add()
myLayerText.kind = LayerKind.TEXT
var myText = myLayerText.textItem
myColor = new SolidColor
myColor.rgb.red = 255
myColor.rgb.green = 0
myColor.rgb.blue = 0
myLayerText.textItem.color = myColor
myText.position = [0,20] // Upper Left
myText.justification = Justification.LEFT
myText.size = 12
myText.contents = myLayerName
myLayerText.name = myLayerName // Or add a fixed string in quotes i.e. 'My Great Layer Name!'
app.preferences.rulerUnits = myRulers
Copy link to clipboard
Copied
TextLayer(app.activeDocument.activeLayer.name);
function TextLayer(text) {
var layers = app.activeDocument.artLayers;
var layer = layers.add();
layer.kind = LayerKind.TEXT;
var textItem = layer.textItem;
textItem.kind = TextType.PARAGRAPHTEXT;
textItem.size = 30;
textItem.position = [10, 10];
textItem.contents = text;
textItem.width = new UnitValue("300 pixels");
textItem.height = new UnitValue("30 pixels");
}