Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Forked from vladocar/layersOrder.js
Last active April 21, 2019 23:20
Show Gist options
  • Save Arahnoid/aeda4f6b78d8177a5134 to your computer and use it in GitHub Desktop.
Save Arahnoid/aeda4f6b78d8177a5134 to your computer and use it in GitHub Desktop.
[Sort A-Z] Sort Photoshop layers alphabeticaly #Photoshop
function sortLayerAZ (layerList) {
var layers;
// check if layer list is provided
if (layerList) {
layers = layerList;
} else {
layers = activeDocument.layers;
}
var len = layers.length;
if (len > 1) {
var layersArray = [];
// store all layers in an array
for (var i = 0; i < len; i++) {
layersArray.push(layers[i]);
}
// remove Background layer from array
var o = layersArray.length;
while(o--) {
if(layersArray[o].hasOwnProperty('name') && layersArray[o].name === 'Background' ) {
layersArray.splice(o,1);
}
}
// sort layer top to bottom
layersArray.sort();
for (i = 0; i < layersArray.length-1; i++) {
layersArray[i].move(layers[i], ElementPlacement.PLACEBEFORE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment