Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript to select background layer and apply solid color

Community Beginner ,
Dec 19, 2021 Dec 19, 2021

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.

TOPICS
Actions and scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Dec 19, 2021 Dec 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}

 

 

 

Translate
Adobe
Mentor ,
Dec 19, 2021 Dec 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}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 19, 2021 Dec 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!!! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 19, 2021 Dec 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}

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 19, 2021 Dec 19, 2021

I spoke too soon! that's it! PERFECT TY!!!!! ❤️

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 19, 2021 Dec 19, 2021

Sorry I couldn't find a way to edit my message. 
I did a little bit of research here: https://graphicdesign.stackexchange.com/questions/33621/restore-photoshop-text-layer-name-auto-updat...

 

And found that when I select the text tool, click into the layer and just hit escape, it renames the layer the value of the text (if that makes sense). I wonder if there's a script that could sort of emulate this that I can use in conjunction with the last one?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2021 Dec 19, 2021

I think yot are clicking or double clicking on the layer's name in the layers Palette to edit the layer's name. Try clicking off the name to select the layer. Do  not edit the layer name.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 19, 2021 Dec 19, 2021

Great thanks JJmack!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2021 Dec 19, 2021

@Geekygreek22317303i6i4 wrote:

Sorry I couldn't find a way to edit my message. 
I did a little bit of research here: https://graphicdesign.stackexchange.com/questions/33621/restore-photoshop-text-layer-name-auto-updat...

 

And found that when I select the text tool, click into the layer and just hit escape, it renames the layer the value of the text (if that makes sense). I wonder if there's a script that could sort of emulate this that I can use in conjunction with the last one?


 

I can't reproduce that and I am not following the problem or request, can you post a screenshot?

 

Via scripting, text layers can have both a name (.name), and contents (.contents) – which may or may not be "coupled" or even the same.

 

If this is simply about renaming many existing layers:

 

https://github.com/Paul-Riggott/PS-Scripts/blob/master/Layer%20Name%20Edit.jsx

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

EDIT: The script posted by jazz-y retains the automated "link" between the text layer content and the text layer name, so if the content is changed the layer name is automatically changed to match. Once the layer name is manually edited, it is no longer "coupled" to the content and will not automatically update with content changes. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 19, 2021 Dec 19, 2021

Sorry that message I posted was after Jazzy figured out the solution for me. I'm all set now, worked perfectly!

Also something I gotta remember going forward, as a couple of you mentioned; I was editing the layer name and not the layer so it caused some of the issues  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2021 Dec 20, 2021

Ah OK then, case closed! Please mark the post/s from jazz-y as the correct answer/s then, thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 20, 2021 Dec 20, 2021

Done, thanks so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2021 Dec 21, 2021
LATEST

 

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)

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines