Thanks, Tom. I created a jsx file with the following content: #target photoshop // Version 2017.6.12 // Given a max size, reduce the quality of the jpeg // until it is small enough var maxSize = 1024 * 1024; var smallEnough = false; var tries = 1; var q = 12; var f = new File('/d/Testout/1meg.jpg'); if (f.exists) f.remove(); if (f.exists) throw('what!'); while ( ! smallEnough && q ) { smallEnough = SaveFile(f, maxSize, q); q--; } SaveFileAll([f.parent + "/", f.name.split(".")[0], "." + f.name.split(".")[1]]); 'DONE ' + q; function SaveFile(inFile, inMaxSize, inQ) { var smallEnough = false; var idsave = stringIDToTypeID( "save" ); var desc78 = new ActionDescriptor(); var idas = stringIDToTypeID( "as" ); var desc79 = new ActionDescriptor(); var idextendedQuality = stringIDToTypeID( "extendedQuality" ); desc79.putInteger( idextendedQuality, inQ ); var idmatteColor = stringIDToTypeID( "matteColor" ); var idmatteColor = stringIDToTypeID( "matteColor" ); var idnone = stringIDToTypeID( "none" ); desc79.putEnumerated( idmatteColor, idmatteColor, idnone ); var idJPEG = stringIDToTypeID( "JPEG" ); desc78.putObject( idas, idJPEG, desc79 ); var idin = stringIDToTypeID( "in" ); desc78.putPath( idin, inFile ); var idcopy = stringIDToTypeID( "copy" ); desc78.putBoolean( idcopy, true ); executeAction( idsave, desc78, DialogModes.NO ); // there is inFile.length but it is wrong on windows 7 if ( inFile.open('r') ) { var a = inFile.read(); inFile.close(); if (a.length <= inMaxSize) smallEnough = true; } return smallEnough; } Running the file in Photoshop CS6 will lead to the following message: Also, when I add the last part of your script it won't work: // Another version that tries to save them all, call in the same loop above // but pass in an array of dir, filename, fileExtension function SaveFileAll(inF) { for (var i = 1; i < 13; i++) { var idsave = stringIDToTypeID( "save" ); var desc78 = new ActionDescriptor(); var idas = stringIDToTypeID( "as" ); var desc79 = new ActionDescriptor(); var idextendedQuality = stringIDToTypeID( "extendedQuality" ); desc79.putInteger( idextendedQuality, i ); var idmatteColor = stringIDToTypeID( "matteColor" ); var idmatteColor = stringIDToTypeID( "matteColor" ); var idnone = stringIDToTypeID( "none" ); desc79.putEnumerated( idmatteColor, idmatteColor, idnone ); var idJPEG = stringIDToTypeID( "JPEG" ); desc78.putObject( idas, idJPEG, desc79 ); var idin = stringIDToTypeID( "in" ); var f = new File( inF[0] + inF[1] + i + inF[2] ); desc78.putPath( idin, f ); var idcopy = stringIDToTypeID( "copy" ); desc78.putBoolean( idcopy, true ); executeAction( idsave, desc78, DialogModes.NO ); } } Where do I have to add ".flatten()"?
... View more