• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
6

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

Participant ,
Feb 04, 2024 Feb 04, 2024

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. 

TOPICS
Actions and scripting , Windows

Views

345

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 04, 2024 Feb 04, 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;
jpgS
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 04, 2024 Feb 04, 2024

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(".")));

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 04, 2024 Feb 04, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2024 Feb 04, 2024

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

thank you so much. That works perfectly. :clinking_glasses:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2024 Feb 05, 2024

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('.');

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2024 Feb 05, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2024 Feb 05, 2024

Copy link to clipboard

Copied

LATEST

Yeah I deal with part numbers and those have all sorts of funny naming.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2024 Feb 04, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines