Skip to content

Instantly share code, notes, and snippets.

@joonaspaakko
Last active December 20, 2019 20:54
Show Gist options
  • Save joonaspaakko/1e729111b8bbd8c2cde038bac588aadd to your computer and use it in GitHub Desktop.
Save joonaspaakko/1e729111b8bbd8c2cde038bac588aadd to your computer and use it in GitHub Desktop.
Photoshop script for selecting all layers, including the background layer.
selectAllLayers();
function selectAllLayers() {
// Select all layers (doesn't include Background)
try {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( stringIDToTypeID('selectAllLayers'), desc, DialogModes.NO );
} catch(e) {}
// Add Background Layer to the selection (if possible)
try {
activeDocument.backgroundLayer;
var bgID = activeDocument.backgroundLayer.id;
var ref = new ActionReference();
var desc = new ActionDescriptor();
ref.putIdentifier(charIDToTypeID('Lyr '), bgID);
desc.putReference(charIDToTypeID('null'), ref);
desc.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection') );
desc.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
} catch(e) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment