Skip to main content
Participant
April 28, 2024
Answered

Droplets and export layer comps to files

  • April 28, 2024
  • 2 replies
  • 941 views

Hello, I'm working on changing many psd files that have to have a yeardate change and then each psd file has 4 layer comps to save out as jpegs.

 

I'm using libraries, actions and droplets to get the result I want, but when the action runs and gets to the part about exporting layer comps the popup window comes up and I have to click "run" and then after that I have to click "ok" that the layer comps were saved.

 

Is there a way to bypass dialog boxes when using actions/droplets? The same thing happens when I used the batch feature too. I know it's only clicking twice, but the goal is to let it run and walk away.

Thanks in advance for any info. Using Photoshop 25.6

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

@Andrew37041986a7pl 

 

Try this script. You might need to change the folder name in the script as I'm not sure if you are using _jpg or _jpeg or something else...

 

/*
All Layer Comps to JPEG.jsx
v1.0, 30th April 2024 - Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/droplets-and-export-layer-comps-to-files/td-p/14585398
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/a-script-that-would-pack-layercomps-into-rgba-channels-and-saving-in-chosen-file-format/m-p/13906491
Info: Suitable for batch processing when recorded into an action.
*/

#target photoshop

if (documents.length > 0) {

    if (activeDocument.layerComps.length) {

        app.togglePalettes();
        var restoreDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;

        try {
            //var theSavePath = Folder.selectDialog("Select the output folder:");
            var theSavePath = Folder('~/Desktop/_jpg');
            if (!theSavePath.exists) {
                theSavePath.create();
            }
        } catch (e) {
            var theSavePath = Folder('~/Desktop/');
        }

        deleteDocumentAncestorsMetadata();
        removeCRSmeta();
        removeXMP();

        for (i = 0; i < activeDocument.layerComps.length; i++) {
            activeDocument.layerComps[i].apply();
            var compName = activeDocument.layerComps[i].name;
            saveCompToJPG();
        }

        app.togglePalettes();
        app.displayDialogs = restoreDialogMode;
        
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    } else {
        alert("The document must contain layer comps!");
    }

} else {
    alert("You must have a document open!");
}


function saveCompToJPG() {
    try {
        var filePath = new File(theSavePath + "/" + compName + ".jpg");
        var jpgOptns = new JPEGSaveOptions();
        jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
        jpgOptns.embedColorProfile = true;
        jpgOptns.matte = MatteType.NONE;
        jpgOptns.quality = 12;
        activeDocument.saveAs(filePath, jpgOptns, true, Extension.LOWERCASE);
    } catch (e) {
        alert("Error!" + "\r" + e + ' ' + e.line);
    }
}

function removeXMP() {
    //https://community.adobe.com/t5/photoshop/script-to-remove-all-meta-data-from-the-photo/td-p/10400906
    if (!documents.length) return;
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

function removeCRSmeta() {
    //community.adobe.com/t5/photoshop/remove-crs-metadata/td-p/10306935
    if (!documents.length) return;
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
    XMPUtils.removeProperties(xmp, XMPConst.NS_CAMERA_RAW, "", XMPConst.REMOVE_ALL_PROPERTIES);
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

function deleteDocumentAncestorsMetadata() {
    whatApp = String(app.name); //String version of the app name
    if (whatApp.search("Photoshop") > 0) { //Check for photoshop specifically, or this will cause errors
        if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
        // Begone foul Document Ancestors!
        xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
        app.activeDocument.xmpMetadata.rawData = xmp.serialize();
    }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 30, 2024

@Andrew37041986a7pl 

 

Try this script. You might need to change the folder name in the script as I'm not sure if you are using _jpg or _jpeg or something else...

 

/*
All Layer Comps to JPEG.jsx
v1.0, 30th April 2024 - Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/droplets-and-export-layer-comps-to-files/td-p/14585398
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/a-script-that-would-pack-layercomps-into-rgba-channels-and-saving-in-chosen-file-format/m-p/13906491
Info: Suitable for batch processing when recorded into an action.
*/

#target photoshop

if (documents.length > 0) {

    if (activeDocument.layerComps.length) {

        app.togglePalettes();
        var restoreDialogMode = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;

        try {
            //var theSavePath = Folder.selectDialog("Select the output folder:");
            var theSavePath = Folder('~/Desktop/_jpg');
            if (!theSavePath.exists) {
                theSavePath.create();
            }
        } catch (e) {
            var theSavePath = Folder('~/Desktop/');
        }

        deleteDocumentAncestorsMetadata();
        removeCRSmeta();
        removeXMP();

        for (i = 0; i < activeDocument.layerComps.length; i++) {
            activeDocument.layerComps[i].apply();
            var compName = activeDocument.layerComps[i].name;
            saveCompToJPG();
        }

        app.togglePalettes();
        app.displayDialogs = restoreDialogMode;
        
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    } else {
        alert("The document must contain layer comps!");
    }

} else {
    alert("You must have a document open!");
}


function saveCompToJPG() {
    try {
        var filePath = new File(theSavePath + "/" + compName + ".jpg");
        var jpgOptns = new JPEGSaveOptions();
        jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
        jpgOptns.embedColorProfile = true;
        jpgOptns.matte = MatteType.NONE;
        jpgOptns.quality = 12;
        activeDocument.saveAs(filePath, jpgOptns, true, Extension.LOWERCASE);
    } catch (e) {
        alert("Error!" + "\r" + e + ' ' + e.line);
    }
}

function removeXMP() {
    //https://community.adobe.com/t5/photoshop/script-to-remove-all-meta-data-from-the-photo/td-p/10400906
    if (!documents.length) return;
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

function removeCRSmeta() {
    //community.adobe.com/t5/photoshop/remove-crs-metadata/td-p/10306935
    if (!documents.length) return;
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
    XMPUtils.removeProperties(xmp, XMPConst.NS_CAMERA_RAW, "", XMPConst.REMOVE_ALL_PROPERTIES);
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

function deleteDocumentAncestorsMetadata() {
    whatApp = String(app.name); //String version of the app name
    if (whatApp.search("Photoshop") > 0) { //Check for photoshop specifically, or this will cause errors
        if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
        var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
        // Begone foul Document Ancestors!
        xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
        app.activeDocument.xmpMetadata.rawData = xmp.serialize();
    }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Participant
April 30, 2024

Thanks again...I don't even begin to think how you know how to do all this. And thanks for the link above. I've used and imported scripts into InDesign before, but not PS.

I'll try this tonight. I think I tell in your script that the files will go to a folder on the desktop called _jpg

Participant
May 1, 2024

I tried your script out and it worked like a charm! This is going to be a huge time saver and I can't thank you enough!

Stephen Marsh
Community Expert
Community Expert
April 28, 2024

Layer Comps to Files is a script that was designed to have a GUI. 

 

These Adobe scripts are a major PITA to edit, although it is possible to hard code in the GUI-driven variables and remove the GUI.

 

What would be easier is to write a new script from scratch which is designed for use in batch automation without a GUI.

 

Can you post a screenshot of the settings currently being used in the GUI and provide examples of how the save files are named and the save location etc?

Participant
April 30, 2024

Thanks for the reply Stephen...Hopefully I attached two screen shots of what you are asking for...these are the two messages that I have to click "run" and "Ok" as the actions runs and gets to the layer comps part. The save location is just a folder on my desktop I'm having all the files go to.

As far as the saved file names...I labeled my layer comps exactly how I want the files named after export so I'm not having a challenge there. Exporting my layer comps will get me the file name I want. Each layer comp is labeled with a specific item # and color code. For example "9CPW_01" and there are 4 layer comps for each .psd

I'm just stuck clicking "Run" and "Ok" on every image

Thanks for your time

Stephen Marsh
Community Expert
Community Expert
April 30, 2024

@Andrew37041986a7pl 

 

The second prompt is easy enough to disable in the script code, however, the GUI is much harder.

 

So a custom script is much easier for me.

 

What is the name of the destination folder on the Desktop?

 

_jpg

 

or

 

_jpeg

 

or something else? (your screenshot was chopped off and only shows the beginning of the path, not the end)