Skip to main content
Participant
December 2, 2022
Question

1- Automatically create a folder in a specific location and the name of the folder is created increm

  • December 2, 2022
  • 1 reply
  • 348 views
Hello friends
I have another problem
I need a script
1- Automatically create a folder in a specific location and the name of the folder is created incrementally each time
2- 2 JPG files and one PSD file will be automatically saved in that folder
I have seen some examples of scripts but none of them do this
 
The working method of this script is similar to what I want, but instead of a file, it should create a folder and save 2 JPG files together, or even if several photos are open in Photoshop, all of them should be saved in that folder.
 
Thank you if anyone knows

 

// 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 = false; // true - false
var jpegQuality = 10; // 1-12
var formatOption = 1; // 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)
    //     // alert("An image must be open and saved before running this script!");
    // }
}
/* Finish Open/Saved Document Error Check - Part B: Catch */

​

 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    December 2, 2022

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

     

    <moved from using the community>