Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Save as with sequential numbering scripting - Help please

New Here ,
Sep 05, 2021 Sep 05, 2021

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

TOPICS
Actions and scripting , macOS
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 05, 2021 Sep 05, 2021

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
//        
...
Translate
Adobe
Community Expert ,
Sep 05, 2021 Sep 05, 2021

 

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. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021
I tried it and it fails on three counts. Is there any chance that someone can fix it? How do I alert Paul Riggot?
Let me explain it via the screenshot:
The winter mountains, The file is saved in the correct folder, it should be saved as a JPG, though. I am missing the dialog (as in  the other screenshot.) It would allow me to change name or location if neccessary..
 
The original JPG has a letter at the end of name -xx. The other file, the couple, has a number at the end. That seems to be the reason why the name is gone and it is just  003, 004 etc. Strange, isn’t it.
 
Thank you

 

 

dialogue.jpgSave as sequential Mistakes.jpg

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 05, 2021 Sep 05, 2021

Paul is no longer working with scripts. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2022 Jan 17, 2022

He was upset with not being fixed Bridge scripting bugs through the years and left forums.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 05, 2021 Sep 05, 2021

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);

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 17, 2022 Jan 17, 2022

@Stephen Marsh 

This code works, but only saves 10 files

Hameed.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2022 Jan 17, 2022
LATEST

 

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:

https://community.adobe.com/t5/photoshop-ecosystem-discussions/save-copy-incrementally-with-javascri...

 

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines