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: xbytor, DavideBarranca, Paul MR

Post Reply
Grrr1337
Posts: 1
Joined: Fri Nov 01, 2019 3:40 pm

Iterating the Layers and renaming

Post by Grrr1337 » Fri Nov 01, 2019 3:47 pm

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: 225
Joined: Mon Jul 25, 2016 12:36 pm

Re: Iterating the Layers and renaming

Post by Kukurykus » Sun Nov 03, 2019 10:58 am

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.

Post Reply