Skip to main content
September 27, 2010
Question

Unlocking Background Layer with lots of other layers

  • September 27, 2010
  • 3 replies
  • 10348 views

I've been looking at the similar questions, but no script has worked perfectly yet. I have a series of phoshop actions that I run on a regular basis. I have two version of each, one for if there's a locked background layer, and one for when its already been unlocked. Otherwise my actions error.

I'd like to simplify the process and have a script run that finds any locked layers (ie: background) and unlocks it, even if there are 15 other layers and even if I have another layer selected. It should also run without errors if there are no locked (background) layers to be found.

I don't know the first thing about writing my own scripts, so can somebody tell me what lines of code I'd need? Thank you Thank you!

This topic has been closed for replies.

3 replies

March 6, 2018

How do I copy this script? text edit and save as a .jsx?

Inspiring
September 27, 2010

Just a couple quick questions:

1. Did you want ALL locked layers in the stack to be unlocked or just the bottom layer on the stack?

2. When you start your action, which layer is active? Or is it random?

September 27, 2010

1) I want all Locked layers (99% of the time this is just the background layer) to be unlocked

2) Random

(thank you for looking into it!)

Inspiring
September 27, 2010

The script below will check all the layers in a document and make sure that there is no layer locking of any kind. Will work with layers in layersets and unlock layersets.

var topLayer = app.activeDocument.layers[0];
app.activeDocument.activeLayer = topLayer;
do{
    unlockLayer();
    selectLayerBelow();
}while(topLayer != app.activeDocument.activeLayer)
function unlockLayer(){
    if(app.activeDocument.activeLayer.isBackgroundLayer ) app.activeDocument.activeLayer.name = 'From Background';
    if(app.activeDocument.activeLayer.allLocked) app.activeDocument.activeLayer.allLocked = false;
    if(app.activeDocument.activeLayer.pixelsLocked) app.activeDocument.activeLayer.pixelsLocked = false;
    if(app.activeDocument.activeLayer.positionLocked) app.activeDocument.activeLayer.positionLocked = false;
    if(app.activeDocument.activeLayer.transparentPixelsLocked) app.activeDocument.activeLayer.transparentPixelsLocked = false;
};
function selectLayerBelow(){
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putBoolean( charIDToTypeID( "MkVs" ), false );
    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};

JJMack
Community Expert
Community Expert
September 27, 2010

ishook187 wrote:

I've been looking at the similar questions, but no script has worked perfectly yet. I have a series of phoshop actions that I run on a regular basis. I have two version of each, one for if there's a locked background layer, and one for when its already been unlocked. Otherwise my actions error.

A Photoshop background layer can not be completely unlocked because a Photoshop background layer does not support transparency that will alway be locked at 100% opacity and fill and can not be changed, no layer can be moved below it and it can not be moved up in the layer stack..  You can convert a background layer to a normal layer which will unlock the layer but it is no longer a background layer.  It is very easy in a script to target the bottom layer and make it a  normal layer just by setting the bottom layer not to be a background.

JJMack
September 27, 2010

I understand the limitations of the Background layer, and don't have a need to keep any properties of the Background layer. The limitations of the background layer have led me to the forums to find a script that can eliminate the limitations. In the end, I'd like to end up with an unlocked Layer 0, without first having to select the Background layer. It should also not error if there isn't a background layer to begin with (like a previously worked on photoshop file)