Ijaz Ahamed
Ijaz Ahamed

Reputation: 19

Photoshop change top text layer name to same as file name

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.

Upvotes: 0

Views: 1588

Answers (2)

Abdul karim mia
Abdul karim mia

Reputation: 1

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);

Upvotes: 0

Ghoul Fool
Ghoul Fool

Reputation: 6949

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.

Upvotes: 1

Related Questions