Skip to main content
Participant
May 8, 2020
Answered

Photoshop Script: Save as JPG with current DATE and TIME

  • May 8, 2020
  • 2 replies
  • 4363 views

Hi folks,

I´m looking for a script which does the following:

 

1. Save current view as JPG

2. Destination folder same as PSD

3. Naming "MN-$DATE-$PSD-NAME-$TIME" (e.g. MN-200508-ClientFlyer-172459)

 

I couldn´t find anything like this in the forum.

Would be such a great time saver for me!

 

(I´m working on Mac and Windows.)

 

Greets,

rufiooo

 

 

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

Hi,

Try following code, you may need to change the time format little bit but this will helpy you.

function exportToJPEG() {
    var docName = app.activeDocument.name.split('.')[0];

    var dateObj = new Date();
    var year = dateObj.getFullYear().toString().substr(-2);
    var month = ("0" + (dateObj.getMonth() + 1)).slice(-2); 
    var date = ("0" + dateObj.getDate()).slice(-2);
    var time = dateObj.getTime();
    var hours = dateObj.getHours()
    var minutes= dateObj.getMinutes();
    var seconds = dateObj.getSeconds();
    var completeTime = hours.toString()+ minutes.toString()+ seconds.toString();
    var completeDate = year.toString() + month.toString() + date.toString();

    var fileName = app.activeDocument.path + "/" + "MN-" + completeDate + "-" + docName + "-" + completeTime + ".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(fileName));
    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();

 

Let us know if this helps you.

Thanks

2 replies

Participant
March 17, 2022

Hi @Charu Rajput, this is a fantastic script! I just had one question, is it possible to specify the time format?

 

Currently when I save, the time misses any leading zeroes.

 

For example 10.05AM becomes 105 rather than 1005. It just mucks up the order when I sort a folder by name.

 

Thank you!

 

Ashley

Charu Rajput
Community Expert
Community Expert
March 17, 2022

@Ashley23402912eqtt 

Use same format for minutes and seconds as used for month and date. 

var minutes= ("0" + dateObj.getMinutes()).slice(-2);
var seconds = ("0" + dateObj.getSeconds()).slice(-2);

 

If required, you can change for hours as well in the similar way.

Best regards
Participant
March 18, 2022

Oh fantastic, thank you @Charu Rajput. I wasn't able to figure that out!

 

🙏

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
May 8, 2020

Hi,

Try following code, you may need to change the time format little bit but this will helpy you.

function exportToJPEG() {
    var docName = app.activeDocument.name.split('.')[0];

    var dateObj = new Date();
    var year = dateObj.getFullYear().toString().substr(-2);
    var month = ("0" + (dateObj.getMonth() + 1)).slice(-2); 
    var date = ("0" + dateObj.getDate()).slice(-2);
    var time = dateObj.getTime();
    var hours = dateObj.getHours()
    var minutes= dateObj.getMinutes();
    var seconds = dateObj.getSeconds();
    var completeTime = hours.toString()+ minutes.toString()+ seconds.toString();
    var completeDate = year.toString() + month.toString() + date.toString();

    var fileName = app.activeDocument.path + "/" + "MN-" + completeDate + "-" + docName + "-" + completeTime + ".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(fileName));
    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();

 

Let us know if this helps you.

Thanks

Best regards
Participant
May 12, 2020

So good! THANK YOU. It works perfectly.

Charu Rajput
Community Expert
Community Expert
May 12, 2020

Great! Glad it helps you.

Best regards