Copy link to clipboard
Copied
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:
@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...
Append means add to the end, so presumably you would just need:
var x = 'my value';
doc.activeLayer.name = noExt + x;
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
Append means add to the end, so presumably you would just need:
var x = 'my value';
doc.activeLayer.name = noExt + x;
Copy link to clipboard
Copied
Yes, I added/appended a suffix, however I still think that it's best to clearly set out the requirements.
Copy link to clipboard
Copied
Not everyone knows the difference between append and prepend. 😉
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
You're welcome... I was going to start with a static variable, but thought that flexibility would be better. Glad you are now sorted!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more