源码
// Incremental Save Script for Photoshop
// Function to add leading zeros
function addLeadingZeros(num, totalLength) {
var numStr = String(num);
while (numStr.length < totalLength) {
numStr = "0" + numStr;
}
return numStr;
}
// Function to get the next incremental filename
function getNextFilename(baseName, extension) {
var folder = app.activeDocument.path;
var files = folder.getFiles(baseName + "_*.psd");
var maxNumber = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var name = file.name;
var match = name.match(/_(\d+)\.psd$/);
if (match) {
var number = parseInt(match[1], 10);
if (number > maxNumber) {
maxNumber = number;
}
}
}
var nextNumber = maxNumber + 1;
var nextNumberStr = addLeadingZeros(nextNumber, 4); // e.g., 0001, 0002, ...
return baseName + "_" + nextNumberStr + extension;
}
function psReminder2() {
alert("123");
// Main script
// try {
// if (app.documents.length > 0) {
// var doc = app.activeDocument;
// var baseName = doc.name.replace(/\.[^\.]+$/, ""); // Remove the extension
// var extension = ".psd";
// var nextFilename = getNextFilename(baseName, extension);
// var saveFile = new File(doc.path + "/" + nextFilename);
// // Save the document as a PSD with the new filename
// var psdSaveOptions = new PhotoshopSaveOptions();
// psdSaveOptions.embedColorProfile = true;
// psdSaveOptions.alphaChannels = true;
// doc.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
// } else {
// alert("No document is open.");
// }
// } catch (e) {
// alert("Error: " + e.message);
// }
}