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 20, 2019

Oh I see. Sorry about that.

If I have a file that is ORIGINAL.psd

Rename script should be

ORIGINAL-Suffix.psd

Suffix would need to be able to change with whatever I need.

Does that make sense?

Stephen Marsh
Community Expert
Community Expert
June 20, 2019

That does make sense!

Do you wish to keep the original file open, or do you wish to close the original file? If close, save before closing or not?