Skip to main content
New Participant
September 1, 2021
Question

PS script to switch between layers

  • September 1, 2021
  • 6 replies
  • 1541 views

I'm searching since months for a solution to use a shortcut to select the one layer above the selected or the layer underneath the selected one.

Because I dodge & burn with curves it's taking ages otherwise, And yes I know about the 50% grey layer 😉

If you have any idea, I know there was a script online called ToggleDBLayers but it's not online any more.

Happy for help!

Michael

This topic has been closed for replies.

6 replies

JJMack
Adobe Expert
September 1, 2021

"I'm searching since months for a solution to use a shortcut to select the one layer above the selected or the layer underneath the selected one."

 

Are you having problem with Photoshop default Shortcut keys (Alt+[ and Alt+])?

 

JJMack
wanokuni
Known Participant
September 1, 2021

those work great when you have a english keybaord and english Photoshop, but when you have a Finnish, swedinsh german... those shortcuts don't work, becuase we have actual letters in the keybaord, Å,Ö, Ä... where the [] are in english keybaord. I have same problem and those shortcuts and they can't be changed in Photoshop so, we either have to using a action or  a script.

wanokuni
Known Participant
September 1, 2021

Here is what I have done so far, it will toggle between the dodge and burn layer, but only when one of them is selected, if you have other layer selected it won't work, I am still learing javascript so, maybe someone can help with this issue.

 

const doc = app.activeDocument;
// Get layer by name
var dodgeLayer = doc.artLayers.getByName("Dodge");
var burnLayer = doc.artLayers.getByName("Burn");


if (doc.activeLayer == dodgeLayer) {
    try {

        doc.activeLayer = burnLayer;

    } catch (e) {}
} else if (doc.activeLayer == burnLayer) {
    try {
        doc.activeLayer = dodgeLayer;

    } catch (e) {}
}

 

 

Kukurykus
Brainiac
September 1, 2021

To always select 'Burn' layer when 'Dodge' or some other is selected, add at end of first condition:

 

 || doc.activeLayer != burnLayer

 

Did you unmark my solution you originally marked as correct in: prevent overwrite files when saving

wanokuni
Known Participant
September 1, 2021

Thanks for the tip, i am also thinking about what if yu have background layer selected and the user try to use this script to select either a dodge or brun layer, Thats what I am not able to find a solution for it yet. 

I have made your asnwer correct could be a mistake, i just fixed it now. 

PECourtejoie
Adobe Expert
September 1, 2021

Just for the sake of completeness, in the English locale, with an english keyboard, one can use Option-Shift-[ (Mac) or Alt+Shift+[ (PC) to select layers below  or Option-Shift-] (Mac) or Alt+Shift+] to select layers above the current layer.

 

BTW, does the following work in German KB with the German Locale: 

Nächste Ebene darunter/darüber auswählen

Alt + , (Komma) oder . (Punkt)

Wahltaste + , (Komma) oder . (Punkt)

from: Standard-Tastaturbefehle

New Participant
September 1, 2021

I know, my problem is that I'm using a German keyboard with an English Photoshop version.

 

Stephen Marsh
Brainiac
September 1, 2021

The built-in keyboard shortcuts and the scripting listener code are limited to visible layers. So if the eye icon is off for a particular layer, it will be skipped.

 

This may or may not be an issue depending on the situation.

 

If you need to select the next layer, regardless of visibility, then there are two scripts to do so:

 

BCM01_ selectBack.jsx

BCM02_ selectForward.jsx

 

BCM Tools - Photoshop scripts

BCM Tools

 

Stephen Marsh
Brainiac
September 1, 2021

And another option here, which is self contained (the previous scripts require another "library" script to be installed):

 

Stephen Marsh
Brainiac
September 1, 2021

I just knocked these up!

 

EDIT: Does not work with layer groups/sets

 

Select the backward layer, regardless of visibility:

 

/*
Select Backward layer by Index.jsx
v1.0 - Stephen Marsh, 1st September 2021
Select the backward layer, relative to the current selected layer, regardless of visibility
Note:
Does not cycle through the bottom layer to the top layer
Does not work with layer sets/groups
*/

var backwardLayer = (getActiveLayerIndex() - 1);
selectLayerByIndex(backwardLayer);

function selectLayerByIndex(index) {
    /* https://github.com/ES-Collection/Photoshop-Scripts/blob/master/Remove%20Unused%20Layers.jsx */
    var ref = new ActionReference();
    ref.putIndex(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref);
    desc.putBoolean(charIDToTypeID("MkVs"), false);
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
}

function getActiveLayerIndex() {
    /* https://github.com/Paul-Riggott/PS-Scripts/blob/master/getLayersetLayerIDs.jsx */
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
    try {
        activeDocument.backgroundLayer;
        return executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1;
    } catch (e) {
        return executeActionGet(ref).getInteger(charIDToTypeID("ItmI"));
    }
}

 

Select the forward layer, regardless of visibility:

 

/*
Select Forward layer by Index.jsx
v1.0 - Stephen Marsh, 1st September 2021
Select the forward layer, relative to the current selected layer, regardless of visibility
Note:
Does not cycle through the top layer to the bottom layer
Does not work with layer sets/groups
*/

var forwardLayer = (getActiveLayerIndex() + 1);
selectLayerByIndex(forwardLayer);

function selectLayerByIndex(index) {
    /* https://github.com/ES-Collection/Photoshop-Scripts/blob/master/Remove%20Unused%20Layers.jsx */
    var ref = new ActionReference();
    ref.putIndex(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref);
    desc.putBoolean(charIDToTypeID("MkVs"), false);
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
}

function getActiveLayerIndex() {
    /* https://github.com/Paul-Riggott/PS-Scripts/blob/master/getLayersetLayerIDs.jsx */
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
    try {
        activeDocument.backgroundLayer;
        return executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1;
    } catch (e) {
        return executeActionGet(ref).getInteger(charIDToTypeID("ItmI"));
    }
}

 

Downloading and Installing Adobe Scripts

New Participant
September 1, 2021

Hey, thanks for your quick reply!

 

I'm using a German one.

 

So can I use any shortcut which I would like to select or do I have to change it in the script?

 

Sorry for asking a very newbie question. 

c.pfaffenbichler
Adobe Expert
September 1, 2021

Save the two scripts as jsx-files into the Presets/Scripts-Folder and the next time you start Photoshop you should be able to assign whatever shortcuts to them via Edit > Keyboad Shortcuts. 

c.pfaffenbichler
Adobe Expert
September 1, 2021

Are you using a non-english keyboard with english Photoshop?

Because there are default keyboard shortcuts – which may be no use in aforementioned case. 

 

Scripting-wise these should work: 

//select next layer below;
var idslct = charIDToTypeID( "slct" );
    var desc6 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref4 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref4.putEnumerated( idLyr, idOrdn, idBckw );
    desc6.putReference( idnull, ref4 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc6.putBoolean( idMkVs, false );
executeAction( idslct, desc6, DialogModes.NO );

 

//select next layer above;
var idslct = charIDToTypeID( "slct" );
    var desc7 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrwr = charIDToTypeID( "Frwr" );
        ref5.putEnumerated( idLyr, idOrdn, idFrwr );
    desc7.putReference( idnull, ref5 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc7.putBoolean( idMkVs, false );
executeAction( idslct, desc7, DialogModes.NO );