Skip to main content
Participating Frequently
November 2, 2020
Answered

Saving multiple files into same folder from actions

  • November 2, 2020
  • 3 replies
  • 5285 views

Hi, I'm trying to find a quick way to save as through either actions or shortcut key. The difficulty is that I am saving from the same file but changing layers. If I create an action this then saves over the last file that I saved but I want it to save each one. It's not a process that I can do as a batch, I just want less clicks and no need to type for the save as into the same folder with the same filename (or automatically change file name to help this).

This topic has been closed for replies.
Correct answer Stephen Marsh

In the short term, you can use Adobe Bridge's Batch Rename command with a Regular Expression:

 

Find: 

(^.+)(-)(.+-.+)(\.[^\.]+$)

 

Replace:

$3-$1

 

 

Then they will sort as you wish:

 

 

EDIT (new code below): When I have time I'll add this renaming to the current script code so that you don't need to use Bridge to Batch Rename.


 

Try this revised code:

 

/*
Composite Combinations From Top Level Layer Sets.jsx
Modified 17th November 2020 by Stephen A Marsh
https://community.adobe.com/t5/photoshop/saving-multiple-files-into-same-folder-from-actions/m-p/11564168

Original Script:
https://github.com/mechanicious/photoshopCompositionComposer

Automatically create variable composite JPEG images based on layer content in top level layer sets/groups.
Final montages are saved to the source directory. Not intended for batch processing.

Example:
- A layer set containing one or more "static" images
- A second layer set containing one or more "variable" backgrounds

Top level layer sets with leading double underscore __ characters are ignored
*/

/* Start Open/Saved Document Error Check - Part A: Try */

main();

function main() {
    try {
        app.activeDocument.path;

        /* Finish Open/Saved Document Error Check - Part A: Try */

        /* Main Code Start */

        var userDisplayDialogsPref = app.displayDialogs;
        app.displayDialogs = DialogModes.ALL;
        app.displayDialogs = DialogModes.NO;

        function getCombinations(arr, n) {
            if (n === 1) {
                var ret = [];
                for (var i = 0; i < arr.length; i++) {
                    for (var j = 0; j < arr[i].length; j++) {
                        ret.push([arr[i][j]]);
                    }
                }
                return ret;
            } else {
                var ret = [];
                for (var i = 0; i < arr.length; i++) {
                    var elem = arr.shift();
                    for (var j = 0; j < elem.length; j++) {
                        var childperm = getCombinations(arr.slice(), n - 1);
                        for (var k = 0; k < childperm.length; k++) {
                            ret.push([elem[j]].concat(childperm[k]));
                        }
                    }
                }
                return ret;
            }
        }

        function hideAllArtLayers() {
            var layerSets = app.activeDocument.layerSets;

            for (var i = 0; i < layerSets.length; i++) {
                if (layerSets[i].artLayers.length) {
                    for (var z = 0; z < layerSets[i].artLayers.length; z++) {
                        layerSets[i].artLayers[z].visible = false;
                    }
                } else {
                    for (var z = 0; z < layerSets[i].layerSets.length; z++) {
                        layerSets[i].layerSets[z].visible = false;
                    }
                }
            }
        }

        function getArtLayerCollectionCollection() {
            var layerSets = app.activeDocument.layerSets,
                artLayerCollectionCollection = [];

            for (var i = 0; i < layerSets.length; i++) {
                var artlayerCollection = [];
                if (layerSets[i].artLayers.length) {
                    for (var z = 0; z < layerSets[i].artLayers.length; z++) {
                        if (layerSets[i].name.indexOf('__') !== 0)
                            artlayerCollection.push(layerSets[i].artLayers[z]);
                    }
                } else {
                    for (var z = 0; z < layerSets[i].layerSets.length; z++) {
                        if (layerSets[i].name.indexOf('__') !== 0)
                            artlayerCollection.push(layerSets[i].layerSets[z]);
                    }
                }
                artLayerCollectionCollection.push(artlayerCollection);
            }

            return artLayerCollectionCollection;
        }

        function combine() {
            var artLayerCollectionCollection = getArtLayerCollectionCollection(),
                artLayerCollectionCollectionCombinations = getCombinations(artLayerCollectionCollection, getLayerSetsCount()),
                continueConfirmation;

            // Error message
            if (!artLayerCollectionCollectionCombinations.length) return alert('Script has aborted. No combinations found. Please make sure no empty groups are present.');

            continueConfirmation = confirm(artLayerCollectionCollectionCombinations.length + " combinations found. Would you like to continue?");

            // Cancel message
            if (!continueConfirmation) return alert('Script has been aborted.');

            // Path to open document
            var savePath = app.activeDocument.path;

            for (var i = 0; i < artLayerCollectionCollectionCombinations.length; i++) {
                hideAllArtLayers();
                var artLayerNames = [];
                for (var z = 0; z < artLayerCollectionCollectionCombinations[i].length; z++) {
                    var artLayer = artLayerCollectionCollectionCombinations[i][z];
                    artLayer.visible = true;
                    // Add hyphen separators between layer set names
                    artLayerNames.push('-' + artLayer.parent.name + '-');
                    artLayerNames.push(artLayer.name);
                }

                var tempFilename = normalizeSaveFileName(artLayerNames.join('')).substr(0, 254);
                // Remove leading hyphen from saved filename retaining the other hyphen separators
                var finalFilename = tempFilename.replace(/^-/, '');
                // Shuffle the filename around a bit...
                var finalFinalFilename = finalFilename.replace(/(^.+)(-)(.+-.+)/, '$3-$1');

                saveDocumentAsJPEG(savePath + '/' + finalFinalFilename);
            }

            // Message on successful script run
            alert(artLayerCollectionCollectionCombinations.length + " JPEG files saved to source directory.");
        }

        function getLayerSetsCount() {
            var layerSets = app.activeDocument.layerSets,
                count = 0;

            for (var i = 0; i < layerSets.length; i++) {
                if (layerSets[i].name.indexOf('__') !== 0) count++;
            }

            return count;
        }

        function normalizeSaveFileName(name) {
            return name;
        }

        function saveDocumentAsJPEG(path) {
            app.activeDocument.saveAs(new File(path + '.jpg'), jpegOptions);
        }

        // JPEG Options
        var jpegOptions = new JPEGSaveOptions();
        jpegOptions.quality = 8; // Quality Level
        jpegOptions.embedColorProfile = true; // or false
        jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE;
        jpegOptions.matte = MatteType.NONE;

        combine();

        app.displayDialogs = userDisplayDialogsPref;

        // Open the destination directory/folder
        var saveDir = Folder(app.activeDocument.path);
        saveDir.execute();

        /* Main Code Finish */
    }

    /* Start Open/Saved Document Error Check - Part B: Catch */

    catch (err) {
        alert("An image must be open and saved before running this script!");
    }
}

/* Finish Open/Saved Document Error Check - Part B: Catch */

 

 

3 replies

Stephen Marsh
Braniac
November 2, 2020

Can you describe in more detail, preferably step-by-step and potentially with screenshots what you are doing and trying to achieve? What does "changing layers" mean? Changing visibility? How many layers and does the count vary?

G0101Author
Participating Frequently
November 2, 2020

Hi, Thank you. 

I have a PSD file with 10 different frame layers that I have made (they are literally frames, as this is to visualise what art will look like in them). I am then creating another layer in the PSD which is the art work that shows in the aperture behind the frames. I am then looking to save this files with each different frame layer into the same folder as quickly as possible as I have a lot of these to do. Clicking between the layers is quick but the save as process is time consuming as it involves multiple clicks and typing to change the file name each time. I did set up an action with an Fkey for the save as which solved the speed issue but the files kept saving over each other (obviously they have the same name at that point).

Anything you could suggest to help would be much appreciated!!

Many Thanks

Stephen Marsh
Braniac
November 3, 2020

(I've saved it manually and the background colour is all good, so it's something to do with the script)


I presume that you are referring to the photoshopCompositionComposer-v0.1.jsx script...

 

It saves a PNG and optionally a PSD, however, there are no explicit save options in the script, so I'm not sure what Photoshop defaults to. Are you referring to the PNG file? If you save as PSD I would hope that there are no colour changes.

 

If this script is what you are looking for, then the original script could be modified.

 

Or were you referring to the Layer Comps to Files script?

 

 

Participating Frequently
November 2, 2020

Use can use Layer Comps, then File-Scripts-Layer Comps To Files.

G0101Author
Participating Frequently
November 2, 2020

Thank you! Can you explain that in more detail? Apologies, I'm not such a pro obviously.

JJMack
Braniac
November 2, 2020

Then you need to save save versions.  You can do that withe an F Key set to an Action that uses the Plug_in Image Processor Pro to save the current document as its next version.  You need to download the Plug-in and install it and record the actions.

JJMack
G0101Author
Participating Frequently
November 2, 2020

Thank you. This looks ideal. I've downloaded and installed it. How do I know run this? I'm looking at having a psd open, making changes to layers then using this for the quick save as option to save jpgs to the same folder.

Many Thanks for your help, much appreciated!

G0101Author
Participating Frequently
November 2, 2020

It looks like I've got an old version of the processor, which seems to be forcing the process to come from Bridge instead of Photoshop.