How To Expand A Group

I have built a function with which you can open and close a group. With the option “recursive” you can say if all subfolders should also be closed or opened.

const photoshop = require("photoshop");

const collapseFolder = (expand = false, recursive = false) => {
    try {
        photoshop.action.batchPlay(
            [
                {
                    _obj: "set",
                    _target: {
                        _ref: [
                            {_property: "layerSectionExpanded"},
                            {
                                _ref: "layer",
                                _enum: "ordinal",
                                _value: "targetEnum",
                            }
                        ],
                    },
                    to: expand,
                    recursive,
                    _options: {dialogOptions: "dontDisplay"},
                },
            ],
            {synchronousExecution: true}
        );
    } catch (e) {
        console.error(e.message);
    }
}

I hope this helps

7 Likes