Skip to main content
Participant
March 22, 2023
Question

Photoshop script saving result in file Javascript

  • March 22, 2023
  • 1 reply
  • 567 views
Hi
 
I'm a total noob in term of javascript, but i find it really useful to ease some redundant task in photoshop,
Here is my question : I'd like to pick one file (in the folder A) and add a suffix to it to gain some time (and nerves). I'd also like for it to be saved in an other folder (in the folder B) and here is the problem... Here is the code that I have :
 
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
try {
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
}
catch (e) {
var theName = myDocument.name;
var thePath = "~/Desktop/VHigh"
};
var theSuffix = " - HD";
// duplicate;
var myDocument = app.activeDocument.duplicate("theCopy", true);
// jpg options;
var jpgopts = new JPEGSaveOptions();
jpgopts.embedProfile = true;
jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
jpgopts.matte = MatteType.NONE;
jpgopts.quality = 10;
myDocument.saveAs((new File(thePath+"/"+theName+theSuffix+".jpg")),jpgopts,true);
// close;
myDocument.close(SaveOptions.DONOTSAVECHANGES);
};
 
I think it has something to do with "myDocument.saveAs((new File(thePath+"/"+theName+theSuffix+".jpg")),jpgopts,true);" but i don't know what to do..
 
Thanks
This topic has been closed for replies.

1 reply

Stephen Marsh
Community Expert
Community Expert
March 22, 2023

@Simon2901718047p8 

 

The script works as is, however, it doesn't do everything that you mention in your text (it doesn't open a file from a folder or save it to another folder).

 

For the save folder selection step to be interactive, you can change:

 

var thePath = myDocument.path;

 

to:

 

var thePath = Folder.selectDialog("Please select the folder to save to...");

 

 

Or you can simply hard-code the path to the folder if this is static and you don't require the user to pick the folder.

 

I'd also suggest adding a check for an open document.