0

I have 1000s of psd file to change top layers as file name. Please help me to crate a script for this.

I want to have a JS-Script, which changes the Text of the Top Layer as file name.

For example: the file name is "20.psd", the script should change the top layer as 20,

After that, it should save the file as png with same file name.

RobC
  • 22,977
  • 20
  • 73
  • 80

2 Answers2

1

Opening your example document 20.psd, will rename the topmost layer 20.psd You'll be wanting to remove the extension. There are various ways of doing it. Like this.

The JavaScript (Photoshop uses the extension .jsx) is quite straight forward.

// call the source document
var srcDoc = app.activeDocument;

// Get the name of the psd document
var docName = app.activeDocument.name;

// Deal with the extension
// Trim of the last four characters
// ie ".psd"
docName = docName.slice(0, -4);


// Rename layer the topmost text layer
srcDoc.layers[0].textItem.contents = docName;

If the topmost layer is a group, it'll rename that. But I'm sure you can fix this.

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
  • Thanks for your help, But I need to change text, not the text layer name, I tried your script but it is changing the top text layer name as file name, but I need to change the text as the file name. https://i.imgur.com/HYfjtQU.png – Ijaz Ahamed Apr 29 '21 at 23:52
  • i replaced srcDoc.layers[0].name = docName; with srcDoc.layers[0].textItem.contents = docName; It's changing text right now, but I'm stuck with extension remove. – Ijaz Ahamed Apr 30 '21 at 00:11
  • Sorry about the mix up with text and layer names. If you know that your **just** using Photoshop files (.psd) then it's easy. You just trim the string of the last four characters. - Not so good if working with .tiff or .py But in this case it's okay :) I've adjusted the code. – Ghoul Fool Apr 30 '21 at 08:37
  • Thank you very much for your time and effort to help me brother, your script is working fine. is there any way to apply this script to all opened documents? – Ijaz Ahamed Apr 30 '21 at 12:34
  • The best way is to record an action. So with one file open. On the Actions palette, record an new action with **New Action...** Give it a name something like "my file renamer". Press record. (The light should be red) Select from the **File** menu **Scripts** and then **Browse...** (select your script) - then script will run. STOP RECORDING and add that to a keyboard shortcut and you are good to go. – Ghoul Fool Apr 30 '21 at 12:42
0
var origDoc = app.activeDocument;

// duplicate the Document with new name
origDoc.duplicate((origDoc.layers[0].textItem.contents), false); 

// close previous one
origDoc.close(SaveOptions.DONOTSAVECHANGES); 
// (SaveOptions.SAVECHANGES);
Ryan M
  • 18,333
  • 31
  • 67
  • 74