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

script to save as jpeg

Participant ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

I have a single folder with 1 PSD file in it, I have edited that file and I want to save that PSD file as jpeg with below properties, I need script which can save the photoshop file to jpeg in same folder where PSD file is and also with same file naming.

 

Properties: Quality 12 : Maximum and Scan value 3 

TOPICS
Actions and scripting

Views

6.4K

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 , Apr 30, 2020 Apr 30, 2020

That you can easily do by fetching the path and name of the document as follows

 

app.activeDocument.path

and

app.activeDocument.name.split('.')[0] // This give you a name of the document without extension

 

Although, I have updated the script. To run on multiple files you can loop on files of the folder. The above script will run on the document which is currently open and active. To run the script on multiple documents, this needs to be changed slightly.

 

Thanks

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hello,

Try following method to export the document into JPEG

 

 

function exportToJPEG() {
    var fullFilePath = app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.jpeg'
    var idsave = stringIDToTypeID("save");
    var desc5 = new ActionDescriptor();
    var idas = stringIDToTypeID("as");
    var desc6 = new ActionDescriptor();
    var idextendedQuality = stringIDToTypeID("extendedQuality");
    desc6.putInteger(idextendedQuality, 12);
    var idscans = stringIDToTypeID("scans");
    desc6.putInteger(idscans, 5);
    var idmatteColor = stringIDToTypeID("matteColor");
    var idmatteColor = stringIDToTypeID("matteColor");
    var idnone = stringIDToTypeID("none");
    desc6.putEnumerated(idmatteColor, idmatteColor, idnone);
    var idJPEG = stringIDToTypeID("JPEG");
    desc5.putObject(idas, idJPEG, desc6);
    var idin = stringIDToTypeID("in");
    desc5.putPath(idin, new File(fullFilePath));
    var iddocumentID = stringIDToTypeID("documentID");
    desc5.putInteger(iddocumentID, 219);
    var idlowerCase = stringIDToTypeID("lowerCase");
    desc5.putBoolean(idlowerCase, true);
    var idsaveStage = stringIDToTypeID("saveStage");
    var idsaveStageType = stringIDToTypeID("saveStageType");
    var idsaveSucceeded = stringIDToTypeID("saveSucceeded");
    desc5.putEnumerated(idsaveStage, idsaveStageType, idsaveSucceeded);
    executeAction(idsave, desc5, DialogModes.NO);
}


exportToJPEG();

 

 

Use your path while calling the method exportToJPEG.

Hope this helps.

Best regards

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

with this script jpeg will be saved on desktop, it should be saved in same directory where psd file is. becaz i have around 100 folders wiht 1100 psds

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

That you can easily do by fetching the path and name of the document as follows

 

app.activeDocument.path

and

app.activeDocument.name.split('.')[0] // This give you a name of the document without extension

 

Although, I have updated the script. To run on multiple files you can loop on files of the folder. The above script will run on the document which is currently open and active. To run the script on multiple documents, this needs to be changed slightly.

 

Thanks

Best regards

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

LATEST

thanks a lot, it works 

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Does this work? 

// 2012, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// create folder if it does not exist;
var folderString = docPath+"/"+basename;
if (Folder(folderString).exists == false) {new Folder(folderString).create()};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 12;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
jpegOptions.scans = 3;
//save jpg as a copy:
thedoc.saveAs((new File(folderString+"/"+basename+".jpg")),jpegOptions,true);
};

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