Save as JPEG in origin image folder with custom prefix in the name

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

jinling288
Posts: 1
Joined: Fri Dec 02, 2022 9:19 pm

Save as JPEG in origin image folder with custom prefix in the name

Post by jinling288 »

I have a great Javascript .jsx that I've found online back in 2015. It works like a charm! It saves the opened in Photoshop file with 1 click as high quality JPEG in the same folder as an original file:

Code: Select all

#target photoshop

var saveFile = new File(activeDocument.path);

// =======================================================

var idsave = charIDToTypeID( "save" );

    var desc8 = new ActionDescriptor();

    var idAs = charIDToTypeID( "As  " );

        var desc9 = new ActionDescriptor();

        var idEQlt = charIDToTypeID( "EQlt" );

        desc9.putInteger( idEQlt, 12 );

        var idMttC = charIDToTypeID( "MttC" );

        var idMttC = charIDToTypeID( "MttC" );

        var idNone = charIDToTypeID( "None" );

        desc9.putEnumerated( idMttC, idMttC, idNone );

    var idJPEG = charIDToTypeID( "JPEG" );

    desc8.putObject( idAs, idJPEG, desc9 );

    var idIn = charIDToTypeID( "In  " );

    desc8.putPath( idIn, new File( saveFile ) );

    var idDocI = charIDToTypeID( "DocI" );

    desc8.putInteger( idDocI, 35 );

    var idCpy = charIDToTypeID( "Cpy " );

    desc8.putBoolean( idCpy, false );

    var idLwCs = charIDToTypeID( "LwCs" );

    desc8.putBoolean( idLwCs, true );

    var idsaveStage = stringIDToTypeID( "saveStage" );

    var idsaveStageType = stringIDToTypeID( "saveStageType" );

    var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );

    desc8.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );

executeAction( idsave, desc8, DialogModes.NO );
But!

Is there a way to modify that script so it can:
  • Add the prefix, something like "_" at the beginning of the file (i.e. "_Image.jpg")
    Close the original opened file in Photoshop without saving or asking to save it. I've found this line, but I'm unsure where to add it to the existing script:

Code: Select all

app.activeDocument.close(SaveOptions.no);
It would make this amazing script even more useful and help me save so much time automating the process of saving over 7500 images I'm editing at the moment.

Thanks!
User avatar
Kukurykus
Posts: 506
Joined: Mon Jul 25, 2016 12:36 pm

Re: Save as JPEG in origin image folder with custom prefix in the name

Post by Kukurykus »

Code: Select all

if (documents.length) {
	(jpg = JPEGSaveOptions)
	.quality = 12; with(activeDocument)
		saveAs(File(path + '/_' + name), jpg, true),
		close(SaveOptions.DONOTSAVECHANGES)
}