What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Batch Automation 2 Folder action


MattDavies

New Member
Messages
4
Likes
1
Hi
Its probably been asked before. But i am trying to do an action that takes an image from one file, an image from another file. Runs the action then saves it to a different folder.
Ive tried and tried but to no avail
Is there a way to do it
thanks
 

MarshySwamp

Active Member
Messages
34
Likes
10
You'll need a script to combine images from two separate folders and save to another folder.

I have created many similar scripts.

How are the files named in each folder? Is there a logical, consistent pattern to the naming? Example:

Folder A:
001A.png
002A.png
003A.png

Folder B:
001B.png
002B.png
003B.png

The script would combine 001A.png + 001B.png, with the 001B layer stacked over the top of 001A.

The input folders could be in a fixed location, or the script could ask you to select the input folders.

Then the script would run an action from an action set in the action panel.

Finally, the script would save to a folder. The output folder could be a fixed location, or the script could ask you to select a folder. The file format and options would also need to be known.
 

MarshySwamp

Active Member
Messages
34
Likes
10
I made a quick edit to an old script as an example. This saves as JPEG, but it could be any format that is required. It's just a start point as everybody has different requirements so it's hard to offer generic code.

JavaScript:
/*
Combine Images from 2 Input Folders to Output Folder as JPEG.jsx
https://www.photoshopgurus.com/forum/threads/2-folder-action.78725/
Stephen Marsh, v1.0 - 18th December 2023
*/

#target photoshop

    (function () {

        if (app.documents.length === 0) {

            try {

                // Input folder 1
                var folder1 = Folder.selectDialog("Select the first image folder:");
                if (folder1 === null) {
                    alert('Script cancelled!');
                    return;
                }

                // Input folder 2
                var folder2 = Folder.selectDialog("Select the second image folder:");
                if (folder2 === null) {
                    alert('Script cancelled!');
                    return;
                }

                // Validate input folder selection
                var validateInputDir = (folder1.fsName === folder2.fsName);
                if (validateInputDir === true) {
                    alert("Script cancelled as both the input folders are the same!");
                    return;
                }

                // Limit the file input as required
                var list1 = folder1.getFiles(/\.(png|jpg|jpeg|tif|tiff|psd|psb|webp)$/i);
                var list2 = folder2.getFiles(/\.(png|jpg|jpeg|tif|tiff|psd|psb|webp)$/i);

                // Alpha-numeric sort
                list1.sort();
                list2.sort();

                // Validate that folder 1 & 2 lists are not empty
                var validateEmptyList = (list1.length > 0 && list2.length > 0);
                if (validateEmptyList === false) {
                    alert("Script cancelled as one of the input folders is empty!");
                    return;
                }

                // Validate that the item count in folder 1 & 2 matches
                var validateListLength = (list1.length === list2.length);
                if (validateListLength === false) {
                    alert("Script cancelled as the two input folders don't have equal quantities of images!");
                    return;
                }

                // Output folder
                var saveFolder = Folder.selectDialog("Please select the folder to save to...");

                // Save and set the dialog display settings
                var savedDisplayDialogs = app.displayDialogs;
                app.displayDialogs = DialogModes.NO;

                // JPEG save options
                var jpgOptions = new JPEGSaveOptions();
                jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;
                jpgOptions.embedColorProfile = true;
                jpgOptions.matte = MatteType.NONE;
                jpgOptions.quality = 12;

                // Perform the stacking and saving
                for (var i = 0; i < list1.length; i++) {
                    var doc = open(list1[i]);
                    var docName = doc.name.replace(/\.[^\.]+$/, '');
                    placeFile(list2[i], 100);
                    /*
                    var actionName = "Molten Lead"; // Action to run
                    var actionSet = "Default Actions"; // Action set folder
                    app.doAction(actionName,actionSet);
                    */
                    doc.saveAs(new File(saveFolder + '/' + docName), jpgOptions);
                    doc.close(SaveOptions.DONOTSAVECHANGES);
                }

                // End of script
                app.displayDialogs = savedDisplayDialogs;
                app.beep();
                var listCount = list1.length;
                alert('Script completed!' + '\r' + listCount + ' JPEG files saved to:' + '\r' + saveFolder.fsName);

            } catch (e) {
                while (app.documents.length > 0) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                alert("If you see this message, something went wrong!" + "\r" + e + ' ' + e.line);
            }

        } else {
            alert('Please close all open documents before running this script!');
        }

        function placeFile(file, scale) {
            try {
                var idPlc = charIDToTypeID("Plc ");
                var desc2 = new ActionDescriptor();
                var idnull = charIDToTypeID("null");
                desc2.putPath(idnull, new File(file));
                var idFTcs = charIDToTypeID("FTcs");
                var idQCSt = charIDToTypeID("QCSt");
                var idQcsa = charIDToTypeID("Qcsa");
                desc2.putEnumerated(idFTcs, idQCSt, idQcsa);
                var idOfst = charIDToTypeID("Ofst");
                var desc3 = new ActionDescriptor();
                var idHrzn = charIDToTypeID("Hrzn");
                var idPxl = charIDToTypeID("#Pxl");
                desc3.putUnitDouble(idHrzn, idPxl, 0.000000);
                var idVrtc = charIDToTypeID("Vrtc");
                var idPxl = charIDToTypeID("#Pxl");
                desc3.putUnitDouble(idVrtc, idPxl, 0.000000);
                var idOfst = charIDToTypeID("Ofst");
                desc2.putObject(idOfst, idOfst, desc3);
                var idWdth = charIDToTypeID("Wdth");
                var idPrc = charIDToTypeID("#Prc");
                desc2.putUnitDouble(idWdth, idPrc, scale);
                var idHght = charIDToTypeID("Hght");
                var idPrc = charIDToTypeID("#Prc");
                desc2.putUnitDouble(idHght, idPrc, scale);
                var idAntA = charIDToTypeID("AntA");
                desc2.putBoolean(idAntA, true);
                executeAction(idPlc, desc2, DialogModes.NO);
            } catch (e) {}
        }
    }());

Instructions for saving and using the code here:

 

Top