Copy link to clipboard
Copied
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.
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;
jpgS
...
Copy link to clipboard
Copied
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(".")));
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
thank you so much. That works perfectly. :clinking_glasses:
Copy link to clipboard
Copied
This removes just the file extension if your filename has multiple dots:
var Name = activeDocument.name.split('.');
Name.length --;
Name = Name.join('.');
Copy link to clipboard
Copied
Yes, you are correct. I use this, because I never have multiple dots in my file names. It could be an issue for others.
Copy link to clipboard
Copied
Yeah I deal with part numbers and those have all sorts of funny naming.
Copy link to clipboard
Copied
Another recent discussion: