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

Batch process many PSD files to "Quick export as PNG"

Community Beginner ,
Apr 18, 2023 Apr 18, 2023

Hi all, 

 

I've been racking my brains and the forums/Google et al for a day to try and find a working solution for my problem. I'm trying to have a script run through either a folder of psd files, or, a bunch of open psd files and quick export each of them to png. I'm part way there,  I have a working script that successfully does them one at once; 

 

 

var document = app.activeDocument;

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

var saveIn = File("myLocalPathHere" + Name + ".png");

document.exportDocument(saveIn, ExportType.SAVEFORWEB);

 

 

Where myLocalPathHere is my actual physical path to the output folder. 

If I open this script in Photoshop it will run fine on the currently displayed document but no more.

My skills are basic at best so I'm trying to find if someone's done this before and could point me in the right direction? 

Thanks! D

TOPICS
Actions and scripting , macOS
3.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 , Apr 18, 2023 Apr 18, 2023

I adapted the following scripts back in 2019 from another script, I'd probably do things differently now, but they should serve the intended purpose. Check the code you may wish to disable the sRGB conversion and or enable the flatten option.

 

Using Save:

 

#target photoshop

// Batch Save As sRGB PNG.jsx

displayDialogs = DialogModes.NO

// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx

if (BridgeTalk.appName == "photoshop")
...
Translate
Adobe
Community Expert ,
Apr 18, 2023 Apr 18, 2023

I'll post code for this later when I have more time.

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 Beginner ,
Apr 18, 2023 Apr 18, 2023
Thank you! Much appreciated!
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 ,
Apr 18, 2023 Apr 18, 2023

I adapted the following scripts back in 2019 from another script, I'd probably do things differently now, but they should serve the intended purpose. Check the code you may wish to disable the sRGB conversion and or enable the flatten option.

 

Using Save:

 

#target photoshop

// Batch Save As sRGB PNG.jsx

displayDialogs = DialogModes.NO

// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx

if (BridgeTalk.appName == "photoshop") {
    app.bringToFront;
    
    var inputFolder = Folder.selectDialog("Select the source folder that contains the files to save as PNG:");

    if (inputFolder != null) {
        // Add/remove file types as necessary
        var fileList = inputFolder.getFiles(/\.(psd|psb|tif?f|jpe?g|png)$/i);
        var outputFolder = inputFolder;

        for (var i = 0; i < fileList.length; i++) {
            if (fileList[i] instanceof File) {
                var document = open(fileList[i]);
                var documentName = fileList[i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension

                while (app.documents.length) {
                    var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");

                    // document.flatten (); // Disable flatten image step

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    function ConvertTosRGBProfile() {
                        app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
                    }
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    var pngOptions = new PNGSaveOptions();
                    pngOptions.compression = 0
                    pngOptions.interlaced = false;
                    app.activeDocument.saveAs(newFile, pngOptions, true, Extension.LOWERCASE);
                    app.activeDocument.close();

                }
            }
            if (i == fileList.length - 1) {
                alert("The files have been saved as PNG files!");
            }
        }
    }
}

 

 

 Using Export/Save for Web:

 

#target photoshop

// Batch Export SfW sRGB PNG.jsx

displayDialogs = DialogModes.NO

// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx

if (BridgeTalk.appName == "photoshop") {
    app.bringToFront;

    var inputFolder = Folder.selectDialog("Select the source folder that contains the files to export as PNG:");

    if (inputFolder != null) {
        // Add/remove file types as necessary
        var fileList = inputFolder.getFiles(/\.(psd|psb|tif?f|jpe?g|png)$/i);
        var outputFolder = inputFolder ;

        for (var i = 0; i < fileList.length; i++) {
            if (fileList[i] instanceof File) {
                var document = open (fileList [i]);
                var documentName = fileList [i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension

                while (app.documents.length) {
                    var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");

                    // document.flatten (); // Disable flatten image step

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    function ConvertTosRGBProfile() {
                            app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
                        }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    exportOptions = new ExportOptionsSaveForWeb();
                    exportOptions.format = SaveDocumentType.PNG;
                    exportOptions.PNG8 = false; // false = PNG-24
                    exportOptions.transparency = true; // true = transparent
                    exportOptions.interlaced = false; // true = interlacing on
                    exportOptions.includeProfile = true; // false = don't embedd ICC profile
                    document.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);
                    document.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
            if (i == fileList.length - 1) {
                alert("The files have been saved as PNG files!");
            }
        }
    }
}

 

 

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 Beginner ,
Apr 19, 2023 Apr 19, 2023

Amazing! Worked first time exactly as I needed, thank you for saving me a headache today! Can I ask, are you finding the pngSaveOptions (for example) in a specific resource somewhere? All I could find was documentation from 2020 at best on the CEP Resources github https://github.com/Adobe-CEP/CEP-Resources/tree/master/Documentation/Product%20specific%20Documentat... - is this still valid and the go-to for the info I need do you know? 

Thanks ever so much again, you've saved me so much time!

D

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 ,
Apr 19, 2023 Apr 19, 2023

Yes, the PDF scripting guides are still valid and useful for ExtendScript/JavaScript programming (but not for UXP).

 

An online version:

 

https://theiviaxx.github.io/photoshop-docs/index.html

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 Beginner ,
Apr 20, 2023 Apr 20, 2023

Thanks! Much appreciated!

 

D

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 ,
Apr 18, 2023 Apr 18, 2023
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 Beginner ,
Apr 19, 2023 Apr 19, 2023

Thanks! I'll review these too! 🙂 

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 Beginner ,
Apr 20, 2023 Apr 20, 2023
LATEST

Thank.

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