Skip to main content
Participating Frequently
December 19, 2021
Answered

Javascript to select background layer and apply solid color

  • December 19, 2021
  • 2 replies
  • 1406 views

Hi i need a Javascript to select background layer and apply solid color for photoshop CC 2019. Can anyone give code for this,

Thanks in advance.

This topic has been closed for replies.
Correct answer jazz-y

It looks like you manually changed the name of the first layer and the auto rename is not working. Try this:

 

for (var i=2;i<=1000;i++)
{activeDocument.activeLayer.name=(activeDocument.activeLayer=activeDocument.activeLayer.duplicate()).textItem.contents=i}

 

 

 

2 replies

Kukurykus
Brainiac
December 21, 2021

 

sTT = stringIDToTypeID, cntr = 999; while(cntr)
	(dsc2 = new ActionDescriptor()).putString(sTT('name'), 1000 - --cntr),
	(dsc1 = new ActionDescriptor()).putObject(sTT('new'), sTT('layer'), dsc2),
	dsc1.putBoolean(sTT('copy'), true), executeAction(sTT('make'), dsc1)

 

Brainiac
December 19, 2021

1. Create text layer '1'  with properties like shadows, strokes, etc

2. Select it on layers palette

3. Run script

for (var i=2; i<=1000;i++)
{(activeDocument.activeLayer= activeDocument.activeLayer.duplicate ()).textItem.contents = i}
Participating Frequently
December 19, 2021

Omg that's amazing!!! it worked! Thank you!

The only issue I found was that the layers were named:

"1 Copy 1"

"1 Copy 2"

"1 Copy 3"

etc

 

If there was a name to take the name of the text that's in that layer that would be amazing. 

Either way thank you so much you genius!!! 

jazz-yCorrect answer
Brainiac
December 19, 2021

It looks like you manually changed the name of the first layer and the auto rename is not working. Try this:

 

for (var i=2;i<=1000;i++)
{activeDocument.activeLayer.name=(activeDocument.activeLayer=activeDocument.activeLayer.duplicate()).textItem.contents=i}