Skip to main content
jimm7497115
Inspiring
February 4, 2024
Answered

Save As jpg Script now saving with 'psd.jpg' how can I strip 'psd'

  • February 4, 2024
  • 3 replies
  • 733 views

Hi, 

I've been using a script that came from here:

 

var Name = activeDocument.name;
var jpegfile = new File('D:/folder1/folder2/' + Name);
SaveAsJPEG(jpegfile, 10);
function SaveAsJPEG(saveFile, jpegQuality){
var doc = activeDocument;
if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}


and it works great, but I wanted to adapt it to a different file that's saved already as .psd file. So, I changed: 
var jpegfile = new File('D:/folder1/folder2/' + Name);
to:

var jpegfile = new File('C:/users/me/Documents/folder2/' + Name);


The problem is now I'm left with '.psd.jpeg' as the file extension. Other than adding a Duplicate document action in a can't fix it. How do I strip '.psd'? 

I've searched but, I'm dyslexic and the answers given to other questions seems very specific to their issue.
 

Thank you. 

This topic has been closed for replies.
Correct answer Chuck Uebele

I use the split function to get rid of extensions. Just change the first line of your script. I should look like this:

var Name = activeDocument.name.split('.')[0];
var jpegfile = new File('D:/folder1/folder2/' + Name);
SaveAsJPEG(jpegfile, 10);
function SaveAsJPEG(saveFile, jpegQuality){
var doc = activeDocument;
if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}

3 replies

Stephen Marsh
Community Expert
Community Expert
February 4, 2024
Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
February 4, 2024

I use the split function to get rid of extensions. Just change the first line of your script. I should look like this:

var Name = activeDocument.name.split('.')[0];
var jpegfile = new File('D:/folder1/folder2/' + Name);
SaveAsJPEG(jpegfile, 10);
function SaveAsJPEG(saveFile, jpegQuality){
var doc = activeDocument;
if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}
jimm7497115
Inspiring
February 4, 2024

thank you so much. That works perfectly. 🥂

c.pfaffenbichler
Community Expert
Community Expert
February 4, 2024

There are several options. 

You could, for example, slice the String according to the position of ».« – that obviously is if the file’s name contains only one ».«. 

var Name = "hgi aefzieo bgroig.psd";
alert (Name.slice(0,Name.indexOf(".")));

 

jimm7497115
Inspiring
February 4, 2024

so what do I do with that information? As I said, I don't understand javascript. The files I'm dealing with are "name.psd" and I was hoping for 'just stick this in  on line two' or something.   Thanks.