Skip to main content
Inspiring
April 30, 2020
Answered

script to save as jpeg

  • April 30, 2020
  • 1 reply
  • 7331 views

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 

This topic has been closed for replies.
Correct answer Charu Rajput

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

1 reply

Charu Rajput
Community Expert
Community Expert
April 30, 2020

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
Inspiring
April 30, 2020

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

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
April 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

Best regards