Skip to main content
Participant
January 10, 2013
Answered

How to copy filename and paste as text in Photoshop

  • January 10, 2013
  • 2 replies
  • 7227 views

I have about 1500 files each with a unique filename. For each image I want to copy that individual filename and paste it into the document as a text layer at a certain location say .25 inches from the bottom right corner. I need it as a text layer as I still need to change minor things.

It would be great to choose the font and size. I also want to be able to copy the file type  if possible. So it would be "filename.png"

I have Photoshop CS5 & CS6. If this is easier with another program like InDesign let me know.

Thanks!

This topic has been closed for replies.
Correct answer c.pfaffenbichler

You may want to search the Forum/web, I expect there are some Scripts about for this task.

This one sets the position in pixels and not inches.

// add document name in text layer;

#target photoshop

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 basename = docName.match(/(.*)\.[^\.]+$/)[1];

//getting the location;

//var docPath = myDocument.path;

// make the layer;

var myLayerRef = myDocument.artLayers.add();

myLayerRef.kind = LayerKind.TEXT;

myLayerRef.name = "text";

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 = 255;

newColor.rgb.green = 255;

newColor.rgb.blue = 255;

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 = docName;

app.preferences.rulerUnits = originalUnits;

};

//that’s it; thanks to xbytor;

2 replies

Participant
October 20, 2014

I have CC2014 and I don't know why but the text appear 2,88 points. I tried on cs6 with 45 points and it's work,

Can you help me

c.pfaffenbichler
Community Expert
Community Expert
October 21, 2014

An DOM text size-related issue has been introduced with the last CC2014 update, you can use AM code instead.

Did CC 2014.2 break textItem.size?

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
January 11, 2013

You may want to search the Forum/web, I expect there are some Scripts about for this task.

This one sets the position in pixels and not inches.

// add document name in text layer;

#target photoshop

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 basename = docName.match(/(.*)\.[^\.]+$/)[1];

//getting the location;

//var docPath = myDocument.path;

// make the layer;

var myLayerRef = myDocument.artLayers.add();

myLayerRef.kind = LayerKind.TEXT;

myLayerRef.name = "text";

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 = 255;

newColor.rgb.green = 255;

newColor.rgb.blue = 255;

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 = docName;

app.preferences.rulerUnits = originalUnits;

};

//that’s it; thanks to xbytor;

Participant
January 11, 2013

Thanks so much, this is perfect! I did search the forums earlier but couldn't find anything.

There is one more thing. Is there a simple way to add a search and replace for the text content? I also have not been able to find this.

For example I want certain characters that are not allowed in filenames like colons ":"

So I want to be able to search for "/" in the text content of the layer and replace with ":"

Thanks again.

c.pfaffenbichler
Community Expert
Community Expert
January 11, 2013

That works! Thanks for the help, I am a bit new at scripting.


You’re welcome.

Check out ESTK’s Help > Object Model Viewer > Core JavaScript Classes if you want to get an overview about what Properties and Methods exist for the various Classes; the text in this instance for example is a String.