Skip to main content
Carlos Rendon
Inspiring
June 19, 2019
Answered

Script to rename file in Photshop (before naming)

  • June 19, 2019
  • 2 replies
  • 10884 views

Hello everyone ,   I have no knowledge of scripting just wondering if any of you can help.  

I am wanting to create an action that will DUPLICATE the image then FLATTEN then rename the file to {FILENAME}-whatever I want   (before saving )   i want the tab on the top of photoshop to say {FILENAME} -whatever I want ... 

I have no idea how to do the renaming?   can I rename files in photoshop like in Bridge or LR?   

thank you for your help !

This topic has been closed for replies.
Correct answer Stephen Marsh

Here you go, try this code:

#target photoshop

// Dupe Original File with -Suffix.jsx

var origDoc = app.activeDocument

var baseName = origDoc.name.replace(/\.[^\.]+$/, '');

var sep = String ("-");

var suffix = prompt("Enter Suffix:", "Suffix");

var dupeName = baseName + sep + suffix;

origDoc.duplicate((dupeName), true);

// Optional Step: remove the // comment characters to enable

origDoc.close(SaveOptions.DONOTSAVECHANGES); // (SaveOptions.SAVECHANGES)

Copy the 10 lines of code above, paste into a plain text editor (not a word processor), then save the plain text file with a .jsx extension, ensuring that it only has .jsx and NOT a double extension such as .jsx.txt

Then drop the file into your application/program folder for Photoshop/Presets/Scripts and restart Photoshop.

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
June 20, 2019

Here you go, try this code:

#target photoshop

// Dupe Original File with -Suffix.jsx

var origDoc = app.activeDocument

var baseName = origDoc.name.replace(/\.[^\.]+$/, '');

var sep = String ("-");

var suffix = prompt("Enter Suffix:", "Suffix");

var dupeName = baseName + sep + suffix;

origDoc.duplicate((dupeName), true);

// Optional Step: remove the // comment characters to enable

origDoc.close(SaveOptions.DONOTSAVECHANGES); // (SaveOptions.SAVECHANGES)

Copy the 10 lines of code above, paste into a plain text editor (not a word processor), then save the plain text file with a .jsx extension, ensuring that it only has .jsx and NOT a double extension such as .jsx.txt

Then drop the file into your application/program folder for Photoshop/Presets/Scripts and restart Photoshop.

Carlos Rendon
Inspiring
June 20, 2019

Oh wow! Thank you so much! I am going to try that right now and i will let you know

Stephen Marsh
Community Expert
Community Expert
June 20, 2019

Apologies, remove lines 9 & 10 from my previous post or change line 10 to include the double forward // comment slashes to disable the code:

// origDoc.close(SaveOptions.DONOTSAVECHANGES); // (SaveOptions.SAVECHANGES)

Stephen Marsh
Community Expert
Community Expert
June 19, 2019

Hello everyone ,   I have no knowledge of scripting just wondering if any of you can help.  

I am wanting to create an action that will DUPLICATE the image then FLATTEN then rename the file to {FILENAME}-whatever I want   (before saving )   i want the tab on the top of photoshop to say {FILENAME} -whatever I want ... 

I have no idea how to do the renaming?   can I rename files in photoshop like in Bridge or LR?   

thank you for your help !

I'm slightly confused...

Lets say you have a file:

originalFILEname.psd

The script will dupe/flatten and rename, should the result be:

originalFILEname-Suffix

or

originalFILEname- Suffix

or

originalFILEname - Suffix

or

{originalFILEname}-Suffix

etc?

Can you please provide more detailed info?

Are you Mac or Win based?

Carlos Rendon
Inspiring
June 19, 2019

I'm on Windows 10.

Where is the rename script?

If I use IMAGE > DUPLICATE it will add copy at the end of it. If I change

it then when I run the action it will apply same name to each file. Which

is not what I want.

On Wed, Jun 19, 2019, 5:42 PM Stephen_A_Marsh <forums_noreply@adobe.com>

Stephen Marsh
Community Expert
Community Expert
June 19, 2019

A rename script will need to be written for your exact requirements, which is why answering specific questions is required if somebody is going to help, without wasting time.

Otherwise search the scripting forum and see what you come up with yourself and then the forum can help refine the existing code, however, the forum will still need to know specifics.

Will the suffix be fixed or do you need to type in a new variable suffix each time?