Iterating the Layers and renaming

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Grrr1337
Posts: 8
Joined: Fri Nov 01, 2019 3:40 pm

Iterating the Layers and renaming

Post by Grrr1337 »

Hi everyone,
File->Scripts->Load Files into Stack... and I'm loading a bunch of .pdf files as layers into my newly created .psd -
Since the layers get names such as "LayerName.pdf",
I'm wondering how I would iterate over them and right-trim the ".pdf" from their name? (with JS preferably)
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Iterating the Layers and renaming

Post by Kukurykus »

Code: Select all

(function(){
	for(var i = 0, arg = arguments[0]; i < arg.length; i++) {
		if (arg[i].typename == 'LayerSet') this(arg[i].layers)
		else arg[i].name = String(arg[i].name.split(/\.pdf$/i))
	}
})(activeDocument.layers)
Check your Private Message please.