Copy link to clipboard
Copied
I have two scripts I have been using for a while... one saves a incremenal jpg and the other saves a incrmental PNG... both "should" also retain the current pixle dimentison and DPI. (My old png script used to lower the dpi for some reason)
PNG Script
var saveFolder = new Folder( "D:\\Projects\\_IncSave" );
var saveExt = 'png';
var saveSufixStart = '_';
var saveSufixLength = 3;
// End of user options
var docName = decodeURI ( activeDocument.name );
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];
var saveName = docName[ 1 ]; // activeDocument name with out ext
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix
var saveNumber = files.length + 1;
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
saveAsPNG(saveFile, 9);
function zeroPad ( num, digit ) {
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}
function saveAsPNG(saveFile, quality) {
pngOpts = new PNGSaveOptions();
pngOpts.compression = quality; //0-9
pngOpts.interlaced = false;
activeDocument.saveAs(File(saveFile), pngOpts, true);
}
JPG Script
saveIncrementally();
function saveIncrementally() {
try {
var saveFolder = "D:\\Projects\\_IncSave";
if (!Folder(saveFolder).exists) {
saveFolder = Folder.selectDialog("Select output folder");
if (!saveFolder)
return;
}
var saveExt = 'jpg';
var saveSufixStart = '_';
var saveSufixLength = 3;
// End of user options
//==========================================
var docName = decodeURI ( activeDocument.name );
var dot = docName.lastIndexOf(".");
var saveName = docName.slice(0, dot);
var suffix = zeroPad(0, saveSufixLength);
var myFile = saveFolder + "/" + saveName + "_" + suffix + ".jpg";
while (File(myFile).exists) {
var suffixInteger = parseInt(suffix, 10);
suffixInteger += 1;
suffix = zeroPad(suffixInteger, 3);
myFile = saveFolder + "/" + saveName + "_" + suffix + ".jpg";
}
saveJPEG(myFile, 10)
function saveJPEG(saveFile, qty ) {
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = qty;
app.activeDocument.saveAs( File(saveFile), saveOptions, true );
}
function zeroPad ( num, digit ){
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}
} catch(e) {
alert(e.toString() + "\nLine: " + e.line.toString())
}
}
Can somone that knows how these things work (I copied these form a reddit post that is now locked) and make sure these sctips also save the current colour profile into the image, as if the tick box in the save dialouge is ticked?
The JPEG script works as intended in v2021 and v2024, including both the resolution PPI and ICC profile.
The PNG in v2021 and v2024 includes resolution, however, Document Object Model based scripting PNGSaveOptions has never supported ICC profile inclusion. For that, you need to swap it out for Action Manager code.
You can replace the original DOM function at the end of the PNG script with the following AM function:
function saveAsPNG(saveFile) {
var s2t = function (s) {
...
I'll post the code.
@abUSER23 – try this:
var saveFolder = new Folder("D:\\Projects\\_IncSave");
var saveExt = 'tif';
var saveSufixStart = '_';
var saveSufixLength = 3;
// End of user options
var docName = decodeURI(activeDocument.name);
docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/) : docName = [docName, docName, undefined];
var saveName = docName[1]; // activeDocument name with out ext
var files = saveFolder.getFiles(saveName + '*.' + saveExt);/
...
Copy link to clipboard
Copied
The JPEG script works as intended in v2021 and v2024, including both the resolution PPI and ICC profile.
The PNG in v2021 and v2024 includes resolution, however, Document Object Model based scripting PNGSaveOptions has never supported ICC profile inclusion. For that, you need to swap it out for Action Manager code.
You can replace the original DOM function at the end of the PNG script with the following AM function:
function saveAsPNG(saveFile) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor2.putEnumerated(s2t("method"), s2t("PNGMethod"), s2t("quick")); // "quick" || "moderate" || "thorough"
descriptor2.putEnumerated(s2t("PNGInterlaceType"), s2t("PNGInterlaceType"), s2t("PNGInterlaceNone")); // "PNGInterlaceNone" || "PNGInterlaceAdam7"
descriptor2.putEnumerated(s2t("PNGFilter"), s2t("PNGFilter"), s2t("PNGFilterAdaptive"));
descriptor2.putInteger(s2t("compression"), 6); // 0-9 - Only for "quick", otherwise comment out
descriptor2.putEnumerated(s2t("embedIccProfileLastState"), s2t("embedOff"), s2t("embedOn"));
descriptor.putObject(s2t("as"), s2t("PNGFormat"), descriptor2);
descriptor.putPath(s2t("in"), new File(saveFile));
descriptor.putBoolean(s2t("copy"), true);
descriptor.putBoolean(s2t("lowerCase"), true);
descriptor.putBoolean(s2t("embedProfiles"), true);
executeAction(s2t("save"), descriptor, DialogModes.NO);
}
Hope this helps!
Copy link to clipboard
Copied
Thanks!
Can you check this code... I got it from a chat AI..... it is saving a TIFF as a single layer and saving the profile...
#target photoshop
// Main function
function saveTIFWithIncrementalNumber() {
// Specify the directory to save the TIF files
var saveDir = "D:\\Projects\\_IncSave\\"; // Edit this path
// Ensure the directory exists
var saveFolder = new Folder(saveDir);
if (!saveFolder.exists) {
alert("The specified directory does not exist: " + saveDir);
return;
}
// Get the active document
var doc = app.activeDocument;
// Check if the document is untitled
var docName = doc.name;
if (docName.match(/^Untitled-/i)) {
docName = "untitled";
} else {
docName = doc.name.replace(/\.[^\.]+$/, ''); // Remove file extension
}
// Get the file number increment
var fileNumber = getNextIncrementalNumber(saveDir, docName);
// Create the file name with incremental number
var tifFileName = docName + "." + zeroPad(fileNumber, 4) + ".tif";
// Create the file object
var tifFile = new File(saveDir + tifFileName);
// Duplicate the document to preserve the original
var dupDoc = doc.duplicate();
// Flatten the duplicated document
dupDoc.flatten();
// Save options for TIF file
var tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
tiffSaveOptions.embedColorProfile = true;
// Save the TIF file
dupDoc.saveAs(tifFile, tiffSaveOptions, true, Extension.LOWERCASE);
// Close the duplicated document without saving
dupDoc.close(SaveOptions.DONOTSAVECHANGES);
}
// Function to get the next incremental number for the file
function getNextIncrementalNumber(dir, baseName) {
var files = Folder(dir).getFiles(baseName + ".*.tif");
var maxNumber = 0;
for (var i = 0; i < files.length; i++) {
var fileName = files[i].name;
var match = fileName.match(/(\d+)\.tif$/);
if (match) {
var num = parseInt(match[1], 10);
if (num > maxNumber) {
maxNumber = num;
}
}
}
return maxNumber + 1;
}
// Function to pad the number with zeros
function zeroPad(num, size) {
var s = "000000000" + num;
return s.substr(s.length - size);
}
// Run the main function
saveTIFWithIncrementalNumber();
Copy link to clipboard
Copied
Seems a little defective. It would be easier to just swap out the PNG or JPEG save function for TIFF.
Copy link to clipboard
Copied
how would I do that? I am just copy and paste.. I have no idea what any of the text means.
Copy link to clipboard
Copied
I'll post the code.
@abUSER23 – try this:
var saveFolder = new Folder("D:\\Projects\\_IncSave");
var saveExt = 'tif';
var saveSufixStart = '_';
var saveSufixLength = 3;
// End of user options
var docName = decodeURI(activeDocument.name);
docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/) : docName = [docName, docName, undefined];
var saveName = docName[1]; // activeDocument name with out ext
var files = saveFolder.getFiles(saveName + '*.' + saveExt);// get an array of files matching doc name prefix
var saveNumber = files.length + 1;
//alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));
var saveFile = new File(saveFolder + '/' + saveName + '_' + zeroPad(saveNumber, saveSufixLength) + '.' + saveExt);
saveAsTIFF();
function zeroPad(num, digit) {
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp; }
return tmp;
}
function saveAsTIFF() {
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
// ByteOrder.MACOS or ByteOrder.IBM
tiffSaveOptions.byteOrder = ByteOrder.IBM;
tiffSaveOptions.transparency = false;
tiffSaveOptions.layers = false;
tiffSaveOptions.layerCompression = LayerCompression.ZIP;
tiffSaveOptions.interleaveChannels = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.annotations = true;
tiffSaveOptions.spotColors = true;
tiffSaveOptions.saveImagePyramid = false;
// NONE | JPEG | TIFFLZW | TIFFZIP
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
activeDocument.saveAs(File(saveFile), tiffSaveOptions, true, Extension.LOWERCASE);
}
Copy link to clipboard
Copied
thanks again... this seems to work very well... cheers!
Copy link to clipboard
Copied
@abUSER23 – You’re welcome!
Copy link to clipboard
Copied