Applescript and Photoshop, Layer rename

Hello,

I have an Applescript, which works in tandem with Photoshop to merge image parts in one document and aligns the various layers. Sometimes, however, I need to prepare the merged image for alignment by deleting base images that are not needed and rename (Layer 1 through 7) for the script to work properly (as it calls specific layers in Photoshop). Is there a way to rename Layers with continuous numbering starting with one layer and then moving up a certain number of times. I couldn’t find any function to jump to another layer no matter what its name.

Is this possible? I’d be thankful for any suggestions.

D.

If you have layer folders, it gets more complicated. If so, let me know.

If not:


tell application "Adobe Photoshop"
	set currentDoc to the current document
	set allArtLayers to every art layer of currentDoc
	set theCount to 1
	repeat with aLayer in allArtLayers
		set the name of aLayer to "Layer " & theCount
		set theCount to theCount + 1
	end repeat
end tell


That’s perfect, thanks so much. I did only a small change as my Photoshop file also contains other layers like an icon and an id number. So I did this and it works perfectly.

[AppleScript]
tell application “Adobe Photoshop 2020”
set currentDoc to the current document
set allArtLayers to every art layer of currentDoc whose name begins with “Layer”
set theCount to 7
repeat with aLayer in allArtLayers
set the name of aLayer to "Layer " & theCount
set theCount to theCount - 1
end repeat
end tell
[/AppleScript]

Thanks again.

D.