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

Free script: Remove Selected

Contributor ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

Hi all,

I wanted to share a super simple script that creates a checkbox for removing Channels, Paths, Colour Pickers and/or LayerComps allowing a simple interface in case you don't always wish to remove all.

Can someone test on Windows for me

#target photoshop  

//Created by Dale R, for public and commercial use

//global variables

var w = new Window('dialog', 'Batch Remove');

w.preferredSize = [50,100];

w.alignChildren = "left"; // align checkboxes to left

// creating buttons and checkboxes

var ck1 = w.add("CheckBox { text: 'Paths', value: false}");

var ck2 = w.add("CheckBox { text: 'Channels', value: false}");

var ck3 = w.add("CheckBox { text: 'Layer Comps', value: false}");

var ck4 = w.add("CheckBox { text: 'Colour Samplers', value: false}");

var p = w.add ('panel', undefined)

p.alignment = "center";

var btn = p.add('button', undefined, 'Run')

p.add ("button", undefined, "Cancel")

btn.onClick =  function () {

    w.close();

    if (ck1.value == true) {

    app.activeDocument.pathItems.removeAll();   

        }

    if (ck2.value == true) {

        app.activeDocument.channels.removeAll();

        }

    if (ck3.value == true) {

        app.activeDocument.layerComps.removeAll();

        }

    if (ck4.value == true) {

        app.activeDocument.colorSamplers.removeAll();

        }

}

w.center();

w.show();

TOPICS
Actions and scripting

Views

12.9K

Translate

Translate

Report

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
Adobe
Community Expert ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Stephen_A_Marsh_0-1614083081124.png

 

Is there a way that you can run this script (or a version of it) within an action and selecting certain items but without being promted with the dialogue box every time for each document? I would find it useful to create an action using this script and be able to batch process it over a whole folder of documents that all need paths and alpha channels removed. Thanks!


By @karlssonemil

 

 

The script was designed to be interactive with a GUI, intended for use on one active image at a time.

 

Yes, it is simple enough with a little scripting knowledge to extract the funtions and function calls that you wish to use into a new separate script without a GUI. The script can be recorded into an action for use with automate batch, or extra processing code can be added to the script so that a batch action is not required.

 

Which paths? Normal paths, clipping paths and/or work paths?

 

Which channels? Alpha channels and/or spot channels?

 

Votes

Translate

Translate

Report

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 ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

I would also love the option to run this without the GUI, is there any chance you could adjust the script so it just ticks all the options automatically? Thanks.

Votes

Translate

Translate

Report

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 ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Which exact options?

Votes

Translate

Translate

Report

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 ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Every option except the new file one would be fantastic.

Votes

Translate

Translate

Report

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 ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

@J--Z 

 

Here you go as requested, no GUI... I have not performed exhaustive testing, so use with care and let me know if edits are required... And please do use with care/caution, even more so when batching, the script is obviously "destructive" to non-pixel content and only intended for copies of non-working files.

 

/*
Batch Remove Items 2021 v1.jsx
Stephen Marsh, 2020
19th July 2021 - GUI removed upon request

!!! USE AT YOUR OWN RISK !!!

Based on:
Free script: Remove Selected
https://community.adobe.com/t5/photoshop/free-script-remove-selected/m-p/10104624
*/

#target photoshop

function removeStuff() {

    // Remove all Layer Comps
    app.activeDocument.layerComps.removeAll();

    // Remove all Color Samplers
    app.activeDocument.colorSamplers.removeAll();

    // Remove all Alpha channels
    removeAllAlphaChannelsNotSpot();

    // Remove all Spot channels
    removeAllSpotChannelsNotAlpha();

    // Remove all Clipping Paths
    removeAllClipPaths();

    // Remove all Normal Paths
    removeAllNormalPaths();

    // Remove all Work Paths
    removeAllWorkPaths();

    // Remove all empty layers/groups
    layrs2_DeleteEmptyLayers();

    // Remove all photoshop:DocumentAncestors metadata
    deleteDocumentAncestorsMetadata();

    // Remove all XMP metadata
    removeXMP();

    // Remove all CRS metadata
    removeCRSmeta();

    // Remove all history snapshots
    removeAllHistorySnapshots();

    // Remove all horizontal guides
    removeAllHorizontalGuides();

    // Remove all vertical guides
    removeAllVerticalGuides();

    // Remove all invisible layers/sets
    removeInvisibleLayers(doc);

    //////////////////////////////////////
    // FUNCTIONS
    //////////////////////////////////////

    function removeAllHorizontalGuides() {
        if (documents.length) {
            var count = app.activeDocument.guides.length;
            for (var a = count - 1; a >= 0; a--) {
                if (app.activeDocument.guides[a].direction == Direction.HORIZONTAL) app.activeDocument.guides[a].remove();
            }
        }
    }

    function removeAllVerticalGuides() {
        if (documents.length) {
            var count = app.activeDocument.guides.length;
            for (var a = count - 1; a >= 0; a--) {
                if (app.activeDocument.guides[a].direction == Direction.VERTICAL) app.activeDocument.guides[a].remove();
            }
        }
    }

    function removeAllClipPaths() {
        /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
        // Run for flattened image
        if (app.activeDocument.activeLayer.isBackgroundLayer) {
            // delete clipping paths
            // https://wwwin.hilfdirselbst.ch/foren/Script_um_Pfade_zu_l%F6schen_P372902.html
            // Note selected shape layers will be removed!
            // Invisible selected shape layers will not be removed
            // Deselected shape layers will not be removed
            var myPath = app.activeDocument.pathItems;
            for (n = myPath.length - 1; n >= 0; n--) {
                var value = myPath[n];
                aP = myPath[n];
                if (aP.kind == "PathKind.CLIPPINGPATH") {
                    aP.remove();
                }
            }
        }
        // Run for layered image
        else {
            /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
            // Remove all paths except clipping paths & shape layer paths
            // 2020, use it at your own risk;
            if (app.documents.length > 0) {
                ////// deselect layers //////
                var desc2 = new ActionDescriptor();
                var ref1 = new ActionReference();
                ref1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                desc2.putReference(stringIDToTypeID("null"), ref1);
                executeAction(stringIDToTypeID("selectNoLayers"), desc2, DialogModes.NO);
                ////// get paths //////
                var ref = new ActionReference();
                ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
                var docDesc = executeActionGet(ref);
                if (docDesc.hasKey(stringIDToTypeID("numberOfPaths")) === true) {
                    var theNumber = docDesc.getInteger(stringIDToTypeID("numberOfPaths"));
                    var theArray = new Array;
                    ////// work through paths //////
                    for (var m = 0; m < theNumber + 1; m++) {
                        try {
                            var ref = new ActionReference();
                            ref.putIndex(stringIDToTypeID("path"), m);
                            var pathDesc = executeActionGet(ref);
                            var theName = pathDesc.getString(stringIDToTypeID("pathName"));
                            var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
                            var theIndex = pathDesc.getInteger(stringIDToTypeID("itemIndex"));
                            theArray.push([theName, theKind, theIndex]);
                        } catch (e) { }
                    };
                    ////// delete //////
                    for (var n = theNumber - 1; n >= 0; n--) {
                        /* https://gist.github.com/codewings/725b91ae2c607d96f24e1cc1527b8217
                        phEnumNormalPath -> 1316121936 -> "NrmP"  normalPath
                        phEnumWorkPath -> 1467116368 -> "WrkP"  workPathIndex
                        phClassClippingPath -> 1131180112 -> "ClpP"  clippingPathEPS */
                        if (theArray[n][1] == 1131180112) {
                            var desc4 = new ActionDescriptor();
                            var ref2 = new ActionReference();
                            ref2.putIndex(stringIDToTypeID("path"), theArray[n][2]);
                            desc4.putReference(stringIDToTypeID("null"), ref2);
                            executeAction(stringIDToTypeID("delete"), desc4, DialogModes.NO);
                        };
                    };
                };
            };
        }
    }

    function removeAllNormalPaths() {
        /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
        // Run for flattened image
        if (app.activeDocument.activeLayer.isBackgroundLayer) {
            // delete normal paths
            // https://wwwin.hilfdirselbst.ch/foren/Script_um_Pfade_zu_l%F6schen_P372902.html
            // Note selected shape layers will be removed!
            // Invisible selected shape layers will not be removed
            // Deselected shape layers will not be removed
            var myPath = app.activeDocument.pathItems;
            for (n = myPath.length - 1; n >= 0; n--) {
                var value = myPath[n];
                aP = myPath[n];
                if (aP.kind == "PathKind.NORMALPATH") {
                    aP.remove()
                }
            }
        }
        // Run for layered image
        else {
            /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
            // Remove all normal paths
            // 2020, use it at your own risk;
            if (app.documents.length > 0) {
                ////// deselect layers //////
                var desc2 = new ActionDescriptor();
                var ref1 = new ActionReference();
                ref1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                desc2.putReference(stringIDToTypeID("null"), ref1);
                executeAction(stringIDToTypeID("selectNoLayers"), desc2, DialogModes.NO);
                ////// get paths //////
                var ref = new ActionReference();
                ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
                var docDesc = executeActionGet(ref);
                if (docDesc.hasKey(stringIDToTypeID("numberOfPaths")) == true) {
                    var theNumber = docDesc.getInteger(stringIDToTypeID("numberOfPaths"));
                    var theArray = new Array;
                    ////// work through paths //////
                    for (var m = 0; m < theNumber + 1; m++) {
                        try {
                            var ref = new ActionReference();
                            ref.putIndex(stringIDToTypeID("path"), m);
                            var pathDesc = executeActionGet(ref);
                            var theName = pathDesc.getString(stringIDToTypeID("pathName"));
                            var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
                            var theIndex = pathDesc.getInteger(stringIDToTypeID("itemIndex"));
                            theArray.push([theName, theKind, theIndex]);
                        } catch (e) { }
                    };
                    ////// delete //////
                    for (var n = theNumber - 1; n >= 0; n--) {
                        /* https://gist.github.com/codewings/725b91ae2c607d96f24e1cc1527b8217
                        phEnumNormalPath -> 1316121936 -> "NrmP"  normalPath
                        phEnumWorkPath -> 1467116368 -> "WrkP"  workPathIndex
                        phClassClippingPath -> 1131180112 -> "ClpP"  clippingPathEPS */
                        if (theArray[n][1] == 1316121936) {
                            var desc4 = new ActionDescriptor();
                            var ref2 = new ActionReference();
                            ref2.putIndex(stringIDToTypeID("path"), theArray[n][2]);
                            desc4.putReference(stringIDToTypeID("null"), ref2);
                            executeAction(stringIDToTypeID("delete"), desc4, DialogModes.NO);
                        };
                    };
                };
            };
        }
    }

    function removeAllWorkPaths() {
        /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
        // Run for flattened image
        if (app.activeDocument.activeLayer.isBackgroundLayer) {
            // delete work paths
            // https://wwwin.hilfdirselbst.ch/foren/Script_um_Pfade_zu_l%F6schen_P372902.html
            // Note selected shape layers will be removed!
            // Invisible selected shape layers will not be removed
            // Deselected shape layers will not be removed
            var myPath = app.activeDocument.pathItems;
            for (n = myPath.length - 1; n >= 0; n--) {
                var value = myPath[n];
                aP = myPath[n];
                if (aP.kind == "PathKind.WORKPATH") {
                    aP.remove()
                }
            }
        }
        // Run for layered image
        else {
            /* https://community.adobe.com/t5/photoshop/deleting-ps-paths-automatically/m-p/11060896 */
            // Remove all work paths
            // 2020, use it at your own risk;
            if (app.documents.length > 0) {
                ////// deselect layers //////
                var desc2 = new ActionDescriptor();
                var ref1 = new ActionReference();
                ref1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                desc2.putReference(stringIDToTypeID("null"), ref1);
                executeAction(stringIDToTypeID("selectNoLayers"), desc2, DialogModes.NO);
                ////// get paths //////
                var ref = new ActionReference();
                ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
                var docDesc = executeActionGet(ref);
                if (docDesc.hasKey(stringIDToTypeID("numberOfPaths")) == true) {
                    var theNumber = docDesc.getInteger(stringIDToTypeID("numberOfPaths"));
                    var theArray = new Array;
                    ////// work through paths //////
                    for (var m = 0; m < theNumber + 1; m++) {
                        try {
                            var ref = new ActionReference();
                            ref.putIndex(stringIDToTypeID("path"), m);
                            var pathDesc = executeActionGet(ref);
                            var theName = pathDesc.getString(stringIDToTypeID("pathName"));
                            var theKind = pathDesc.getEnumerationValue(stringIDToTypeID("kind"));
                            var theIndex = pathDesc.getInteger(stringIDToTypeID("itemIndex"));
                            theArray.push([theName, theKind, theIndex]);
                        } catch (e) { }
                    };
                    ////// delete //////
                    for (var n = theNumber - 1; n >= 0; n--) {
                        /* https://gist.github.com/codewings/725b91ae2c607d96f24e1cc1527b8217
                        phEnumNormalPath -> 1316121936 -> "NrmP"  normalPath
                        phEnumWorkPath -> 1467116368 -> "WrkP"  workPathIndex
                        phClassClippingPath -> 1131180112 -> "ClpP"  clippingPathEPS */
                        if (theArray[n][1] == 1467116368) {
                            var desc4 = new ActionDescriptor();
                            var ref2 = new ActionReference();
                            ref2.putIndex(stringIDToTypeID("path"), theArray[n][2]);
                            desc4.putReference(stringIDToTypeID("null"), ref2);
                            executeAction(stringIDToTypeID("delete"), desc4, DialogModes.NO);
                        };
                    };
                };
            };
        }
    }

    function layrs2_DeleteEmptyLayers() {

        /*
        http://madebyvadim.com/layrs/
        */

        // ===========================
        // Delete Empty Layers
        // ===========================

        delEmptyLayers();

        function delEmptyLayers() {
            if (!documents.length) return;
            var layerInfo = getLayerInfo();
            for (var a in layerInfo) { //delete blank layers
                if (layerInfo[a][2] == 'false') deleteLayerByID(Number(layerInfo[a][0]));
            }
            for (var z in layerInfo) {
                if (layerInfo[z][2] == 'true') { //delete empty layerSets
                    selectLayerById(Number(layerInfo[z][0]));
                    if (activeDocument.activeLayer.layers.length == 0) deleteLayerByID(Number(layerInfo[z][0]));
                }
            }
        };

        function deleteLayerByID(ID) {
            var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putIdentifier(charIDToTypeID('Lyr '), ID);
            desc.putReference(charIDToTypeID('null'), ref);
            executeAction(charIDToTypeID('Dlt '), desc, DialogModes.NO);
        };

        function selectLayerById(ID, add) {
            add = (add == undefined) ? add = false : add;
            var ref = new ActionReference();
            ref.putIdentifier(charIDToTypeID('Lyr '), ID);
            var desc = new ActionDescriptor();
            desc.putReference(charIDToTypeID('null'), ref);
            if (add) {
                desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
            }
            desc.putBoolean(charIDToTypeID('MkVs'), false);
            executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
        }

        function getLayerInfo() {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
            var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) + 1;
            var Names = [];
            try {
                activeDocument.backgroundLayer;
                var i = 0;
            } catch (e) {
                var i = 1;
            };
            for (i; i < count; i++) {
                if (i == 0) continue;
                ref = new ActionReference();
                ref.putIndex(charIDToTypeID('Lyr '), i);
                var desc = executeActionGet(ref);
                var layerName = desc.getString(charIDToTypeID('Nm  '));
                var Id = desc.getInteger(stringIDToTypeID('layerID'));
                if (layerName.match(/^<\/Layer group/)) continue;
                var layerType = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID('layerSection')));
                var isLayerSet = (layerType == 'layerSectionContent') ? false : true;
                var boundsDesc = desc.getObjectValue(stringIDToTypeID("bounds"));
                if (boundsDesc.getUnitDoubleValue(stringIDToTypeID('right')) - boundsDesc.getUnitDoubleValue(stringIDToTypeID('left')) == 0) {
                    Names.push([
                        [Id],
                        [layerName],
                        [isLayerSet]
                    ]);
                }
                if (isLayerSet) Names.push([
                    [Id],
                    [layerName],
                    [isLayerSet]
                ]);
            };
            return Names;
        };
    }

    function deleteDocumentAncestorsMetadata() {
        //forums.adobe.com/message/8456985#8456985
        whatApp = String(app.name); //String version of the app name
        if (whatApp.search("Photoshop") > 0) { //Check for photoshop specifically, or this will cause errors
            //Function Scrubs Document Ancestors from Files
            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();
        }
    }

    function removeXMP() {
        //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 removeAllAlphaChannelsNotSpot() {
        // https://community.adobe.com/t5/photoshop/remove-alpha-channel-during-a-batch/m-p/11285697?page=1#M347558
        var myChannel = app.activeDocument.channels;
        for (n = myChannel.length - 1; n >= 0; n--) {
            var value = myChannel[n];
            aC = myChannel[n];
            if (aC.kind == "ChannelType.MASKEDAREA") {
                aC.remove()
            }
        }
    }

    function removeAllSpotChannelsNotAlpha() {
        // https://community.adobe.com/t5/photoshop/remove-alpha-channel-during-a-batch/m-p/11285697?page=1#M347558
        var myChannel = app.activeDocument.channels;
        for (n = myChannel.length - 1; n >= 0; n--) {
            var value = myChannel[n];
            aC = myChannel[n];
            if (aC.kind == "ChannelType.SPOTCOLOR") {
                aC.remove()
            }
        }
    }

    function removeAllHistorySnapshots() {
        /* https://www.photoshopgurus.com/forum/threads/how-to-delete-all-history-states-not-history-or-other-solution-to-a-master-macro.55456/#post-1533719707 */
        var doc = app.activeDocument;
        var hs = doc.historyStates;
        for (var a = hs.length - 1; a >= 0; --a) {
            if (hs[a].snapshot) {
                doc.activeHistoryState = hs[a];
                delHist();
            }
        }

        function delHist() {
            var desc20 = new ActionDescriptor();
            var ref23 = new ActionReference();
            ref23.putProperty(charIDToTypeID('HstS'), charIDToTypeID('CrnH'));
            desc20.putReference(charIDToTypeID('null'), ref23);
            executeAction(charIDToTypeID('Dlt '), desc20, DialogModes.NO);
        }
    }

    /* http://creativetuts.com/photoshop/photoshop-script-code-snippet-archive/ */
    var doc = app.activeDocument;

    function removeInvisibleLayers(doc) {
        for (var i = doc.artLayers.length - 1; 0 <= i; i--) {
            try {
                if (!doc.artLayers[i].visible) {
                    doc.artLayers[i].remove();
                }
            } catch (e) { }
        }
        for (var j = doc.layerSets.length - 1; 0 <= j; j--) {
            removeInvisibleLayers(doc.layerSets[j]);
        }
    }

}
app.activeDocument.suspendHistory("Batch Remove Items 2021 v1", "removeStuff()");

 

 

Votes

Translate

Translate

Report

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 ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Understood! Thanks a lot, been looking for something like this for a long time, very appreciated.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

When i use this in os scripts editor an error ocures at #target photoshop.. what am i doing wrong?

I'm using the os scripts editor but writing in Javascripts..

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Get rid of that first line.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

I've tried that, then i get the error: ReferenceError: Can't find variable: app

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

What exact application/program is "os scripts editor"? Sounds like it doesn't know JavaScript.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

i'm very new to this, so sorry for all of the questions and confusion.

 

I'm using AppleScript 2.7. but i have set it to use JavaScript...thankfull for all of the help i can get!

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Did you ran this code script by Photoshop (File / Scripts / Browse)?

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

No. i haven't been done that and dont know how.

When i enter the code into AppleScript i get an error message on app not found..

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Screenshot 2021-08-25 at 14.50.26.png

This is the error message i recive. I have deleted the first line of the code.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

I believe that you need to use an editor that not only understands JavaScript/ExtendScript – but also understands the Adobe scripting environment as well. As suggested in the other topic thread, for a Mac user I would suggest that you use MS Visual Studio Code for Mac and install the Adobe ExtendScript Debugger extension. Same suggestion for Windows OS, however, the old Adobe ExtendScript Toolkit program still works on Windows (but not on later Mac OS versions) and can be downloaded using the Creative Cloud app (prefs/apps/settings/show older apps).

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

.scpt is wrong file extension.

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

I just told you how to do that. After you save your code in .jsx format run it from Photoshop.

Votes

Translate

Translate

Report

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 ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

What a work of art!

 

I have currently no use for such a script, but wondered if a check all/check none button would be useful, given the long list, or maybe a check all per section? (I mean, it is very easy to say as a non scripter) 

Votes

Translate

Translate

Report

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 ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied


I have currently no use for such a script, but wondered if a check all/check none button would be useful, given the long list, or maybe a check all per section? (I mean, it is very easy to say as a non scripter) 


 

@PECourtejoie â€“ It's a good and useful suggestion. It is easy enough to preset the checkboxes to be either on or off by default (hard coded into the script with value: true or value: false)... But to offer a checkbox to dynamically check/uncheck checkboxes is much harder for me to do as I don't work with ScriptUI very often.

Votes

Translate

Translate

Report

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 ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

I understand, hence the remark in parenthesis.

That said, IMHO, there should be a repository of such code snippets, to create frankenscripts.

Votes

Translate

Translate

Report

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 ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

LATEST

I finally added a button to Check All checkboxes and Uncheck All checkboxes!

 

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 12, 2021 Aug 12, 2021

Copy link to clipboard

Copied

It fails in Multichannel mode.

Votes

Translate

Translate

Report

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 ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

Hello hello hello,

some time later and i sat down this evening and got it to work!!!!!!!!!!! i'm quite excited and thank you very much for everything..

 

I work for a photography studio where we produce a lot of e-com photos with alphas.. is it possible to use this script to remove alphas on a batch? if so.. how? have a great evening or day!!

Votes

Translate

Translate

Report

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 ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied


@Pandos wrote:

... is it possible to use this script to remove alphas on a batch? if so.. how? have a great evening or day!!


 

Sure, save the following code as a script and then record the run of the script into an action, then batch the action.

 

For both alphas and spots:

 

#target photoshop
app.activeDocument.channels.removeAll();

 

 

For only alphas, retaining spots:

 

/*
https://community.adobe.com/t5/photoshop/remove-alpha-channel-during-a-batch/m-p/11285697
*/

#target photoshop

removeAllAlphaChannelsNotSpot();

function removeAllAlphaChannelsNotSpot() {
    try {
        var myChannel = app.activeDocument.channels;
        for (n = myChannel.length - 1; n >= 0; n--) {
            aC = myChannel[n];
            if (aC.kind == "ChannelType.MASKEDAREA" || aC.kind == "ChannelType.SELECTEDAREA") {
                aC.remove()
            }
        }
    } catch (e) {}
}

 

 

For only spots, retaining alphas:

/*
https://community.adobe.com/t5/photoshop/remove-alpha-channel-during-a-batch/m-p/11285697
*/

#target photoshop

removeAllSpotChannelsNotAlpha();

function removeAllSpotChannelsNotAlpha() {
    try {
        var myChannel = app.activeDocument.channels;
        for (n = myChannel.length - 1; n >= 0; n--) {
            aC = myChannel[n];
            if (aC.kind == "ChannelType.SPOTCOLOR") {
                aC.remove();
            }
        }
    } catch (e) {}
}

 

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

 

Votes

Translate

Translate

Report

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