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

Requesting Help Updating Simple Script

Community Beginner ,
Nov 01, 2023 Nov 01, 2023

I'm an accomplished action writer but just can't see the girl in the red dress yet when it comes to scripting. I have a java script that an old coworker, Adam Kobrin, ( thanks again Adam! ) wrote that captures the active psd's file name and renames the active layer that name. I'm hoping that someone out there in the Acosystem can help me by adding a variable in the script that will be appended to file name on the layer.  My intent would be to modify the scripts variable as needed before running.  I will paste script below:

 

/*************************************************************
 
  Rename layer with filename (no extension).
  
  This makes the "product" Smart Object have a non-generic name.
 
**************************************************************/
 
 
 
var doc = app.activeDocument;
 
//remove extension and rename layer
if (doc.name.indexOf(".") !== -1) {
  var noExt = doc.name.replace(/.([^.]*)$/, ""); //remove last dot and after
doc.activeLayer.name = noExt;
 
}
TOPICS
Actions and scripting
436
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 2 Correct answers

Community Expert , Nov 01, 2023 Nov 01, 2023

@See Nelsen â€“ Your post isn't clear to me. As an example, the following alteration will prompt for a suffix and use an underscore separator:

 

/*************************************************************
 
  Rename layer with filename (no extension).
  
  This makes the "product" Smart Object have a non-generic name.
 
**************************************************************/
 
 
 
var doc = app.activeDocument;
 
//remove extension and rename layer
if (doc.name.indexOf(".") !== -1) {
  v
...
Translate
LEGEND , Nov 02, 2023 Nov 02, 2023

Append means add to the end, so presumably you would just need:

var x = 'my value';
doc.activeLayer.name = noExt + x;
Translate
Adobe
Community Expert ,
Nov 01, 2023 Nov 01, 2023

@See Nelsen â€“ Your post isn't clear to me. As an example, the following alteration will prompt for a suffix and use an underscore separator:

 

/*************************************************************
 
  Rename layer with filename (no extension).
  
  This makes the "product" Smart Object have a non-generic name.
 
**************************************************************/
 
 
 
var doc = app.activeDocument;
 
//remove extension and rename layer
if (doc.name.indexOf(".") !== -1) {
  var noExt = doc.name.replace(/.([^.]*)$/, ""); //remove last dot and after
  var thePrompt = prompt("Enter a Suffix:", "");
doc.activeLayer.name = noExt + "_" + thePrompt;
 
}

 

The suffix could be a prefix instead, or it could be hard-coded without a prompt. The separator could be a space or hyphen... Or no separator?

 

Please clearly explain what you are looking for with a before/after naming example, 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
LEGEND ,
Nov 02, 2023 Nov 02, 2023

Append means add to the end, so presumably you would just need:

var x = 'my value';
doc.activeLayer.name = noExt + x;
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 ,
Nov 02, 2023 Nov 02, 2023

@Lumigraphics 

 

Yes, I added/appended a suffix, however I still think that it's best to clearly set out the requirements.

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 ,
Nov 02, 2023 Nov 02, 2023

Not everyone knows the difference between append and prepend. 😉

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 ,
Nov 06, 2023 Nov 06, 2023

Thank you both! I agree I could have been a bit more clear. I did mean append and baking it into the script is what was needed in this instance because I am going to run it in a batch. Lumigraphics you hit it but Stephen I will keep your version as well. The flexibility you scripted could be very handy.  Mad props to you both!

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 ,
Nov 06, 2023 Nov 06, 2023
LATEST

@See Nelsen 

 

You're welcome... I was going to start with a static variable, but thought that flexibility would be better. Glad you are now sorted!

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