Copy link to clipboard
Copied
MY request seemd rather simple when I first asked for help here (months ago). I wa stold there are plenty of scripts for that… only whatever script I tried it didn't deliver. Here is what I am looking for as part of an Action: Save the open file as a jpg…
adding a number (01) at the end of the name …
counting up when I save another version of that file…,
save jpg in the same folder where the original sits
I need the dialogue at the end of the action, should I decide to tje file or ove it to another location.
HELP PLEASE
And here's another one too (I couldn't get the previous to work).
/* https://community.adobe.com/t5/photoshop/automate-save-as-or-export-with-sequential-file-names/m-p/9003836#M88140 */
// Stephen_A_Marsh
// 05-01-2021
// Additional options & menu add
// Rombout Versluijs
// 14-01-2021
// Usage
// - Because its being added to menu it can be hotkeyed
// - useFileName > true adds filename as a prefix
// - jpegQuality > sets save quality . range 1-12
// - formatOption > 1 Progressive
//
...
Copy link to clipboard
Copied
An old one by @Paul Riggott :
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.jpg").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix= zeroPad(Suffix + 1, 2);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".jpg");
SaveJPEG(saveFile, 8);
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
Feel free to add the dialog if you absolutely need it.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Paul is no longer working with scripts.
Copy link to clipboard
Copied
He was upset with not being fixed Bridge scripting bugs through the years and left forums.
Copy link to clipboard
Copied
And here's another one too (I couldn't get the previous to work).
/* https://community.adobe.com/t5/photoshop/automate-save-as-or-export-with-sequential-file-names/m-p/9003836#M88140 */
// Stephen_A_Marsh
// 05-01-2021
// Additional options & menu add
// Rombout Versluijs
// 14-01-2021
// Usage
// - Because its being added to menu it can be hotkeyed
// - useFileName > true adds filename as a prefix
// - jpegQuality > sets save quality . range 1-12
// - formatOption > 1 Progressive
// 2 Optimized Baseline
// 3 Standard Baseline
/*
@@@BUILDINFO@@@ Quick Export as JPG Incremental.jsx 0.0.0.6
*/
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
/*
<javascriptresource>
<name>$$$/JavaScripts/QuickExportAsJPGIncremental/Menu=Quick Export as JPG Incremental...</name>
<category>scriptexport</category>
<menu>export</menu>
<enableinfo>true</enableinfo>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
*/
// alert(documents.length)
#target photoshop
var useFileName = true; // filename as prefix: true - false
var jpegQuality = 10; // 1-12
var formatOption = 3; // 1-3
/* Start Open/Saved Document Error Check - Part A: Try */
savedDoc();
function savedDoc() {
try {
app.activeDocument.path;
/* Finish Open/Saved Document Error Check - Part A: Try */
/* Main Code Start */
// https://forums.adobe.com/message/4453915#4453915
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var savePath = activeDocument.path;
var fileList = [];
if (useFileName) {
var fileList = savePath.getFiles(Name + "*.jpg").sort().reverse();
} else {
var fileList = savePath.getFiles("*.jpg").sort().reverse();
var filtered = [];
for (i in fileList) {
var name = String(fileList[i]).split("/").pop(); // Get filename
name = name.slice(0, name.length - 4); // Split extension from name
// alert(name+" "+!isNaN(name))
// https://stackoverflow.com/questions/651563/getting-the-last-element-of-a-split-string-array
if (!isNaN(name)) filtered.push(name); // Check if name is a number or not > fullname needs to be numbers
}
}
var Suffix = 0;
if (fileList.length) {
if (useFileName) {
Suffix = fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/); // Fix for mix of characters & numbers
Suffix = Number(String(Suffix).slice(String(Suffix).length - 1, String(Suffix).length)); // Fix for Windows
// alert((fileList[0].name).slice(25,26))
// alert((fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)).slice(fileList[0].name.length-5,fileList[0].name.length-4))
// alert((fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)).slice(fileList[0].name.length-1,fileList[0].name.length))
// alert((fileList[0].name).slice(fileList[0].name.length-1,fileList[0].name.length))
// Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)); // strips numbers when mixed
// Suffix = Number(fileList[0].name.match(/\d+$/)); // return true name even when mixed numbers and characters
} else if ((!filtered[0] === undefined) || filtered[0]) {
Suffix = Number(filtered[0].replace(/\.[^\.]+$/, '').match(/\d+$/));
}
}
Suffix = zeroPad(Suffix + 1, 3);
Name = useFileName ? (Name + "_") : "";
var saveFile = File(savePath + "/" + Name + Suffix + ".jpg");
SaveJPEG(saveFile, jpegQuality, formatOption);
}
function SaveJPEG(saveFile, jpegQuality, formatOption) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
if (formatOption === 1) {
jpgSaveOptions.formatOptions = FormatOptions.PROGRESSIVE;
jpgSaveOptions.scans = 3;
} else if (formatOption === 2) {
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
} else {
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
}
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = Number(jpegQuality);
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
/* Main Code Finish */
}
/* Start Open/Saved Document Error Check - Part B: Catch */
catch (err) {
alert(err)
lert("An image must be open and saved before running this script!");
}
}
/* Finish Open/Saved Document Error Check - Part B: Catch */
The whole idea of the script was to "silently" write out sequentually numbered versions to the source folder, it should not overwrite existing files or be saved to another location as it is based on the open source document path which is how it increments to the next number, by checking for the last number in use. Optionally saving to another location would add more complexity.
If you wish to change the zero padding from 001 to 01, change line 86 to:
Suffix = zeroPad(Suffix + 1, 2);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You are correct it stops at 10 for me too, however, I don't have time at the moment to figure out why...
EDIT: A new full featured script for this task here:
This code works OK:
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles("*.jpg").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 3);
//var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".jpg");
var saveFile = File(savePath + "/" + Suffix + ".jpg");
SaveJPEG(saveFile, 8); // JPEG compression level
}
function SaveJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
As does this one:
//https://forums.adobe.com/message/9934728#9934728
//https://forums.adobe.com/message/10673464#10673464
//Save PSD & TGA Numbered Versions.jsx
//https://community.adobe.com/t5/photoshop-ecosystem/scripting-a-save-as-command/m-p/2472387
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
//Name = Name.replace(/\d+$/,'');
try { var savePath = activeDocument.path; }
catch (e) {
alert("You must save this document first!\nTo establish a save path...");
return
}
var fileList = savePath.getFiles(Name + "*.psd").sort().reverse();
var Suffix = 0;
if (fileList.length) Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
Suffix = zeroPad(Suffix + 1, 4);
var saveName = File(savePath + "/" + Name + "_" + Suffix)
SavePSD(saveName);
SaveTARGA(saveName);
alert("Versions " + Name + "_" + Suffix + " saved.")
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function SavePSD(saveFile) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
function SaveTARGA(saveFile) {
SaveOptions = new TargaSaveOptions();
TargaSaveOptions.alphaChannels = true; //include alpha channels, change to false for none
TargaSaveOptions.resolution = TargaBitsPerPixels.TWENTYFOUR; //options of SIXTEEN or THIRTYTWO
TargaSaveOptions.rleCompression = true; //false for no compression
activeDocument.saveAs(saveFile, TargaSaveOptions, true, Extension.LOWERCASE);
};
I stopped testing after 20 saves.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now