Forked from bomberstudios/Copy Layer List.sketchplugin
Last active
August 29, 2015 14:02
-
-
Save marekhrabe/d5bdac33a91c0e05e0ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy Layer List to Clipboard | |
// Change this variables to configure the script: | |
var COPY_LAYER_TYPE = true, | |
TRAVERSE_GROUPS = true, | |
INDENT_GROUPS = true | |
var strRepeat = function(str, qty) { | |
if (qty < 1) return ''; | |
var result = ''; | |
while (qty > 0) { | |
if (qty & 1) result += str; | |
qty >>= 1, str += str; | |
} | |
return result; | |
}; | |
var layers = [[doc currentPage] layers], | |
layers_array = [layers array], | |
layer_tree = "" | |
function copy_text(txt){ | |
var pasteBoard = [NSPasteboard generalPasteboard] | |
[pasteBoard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil] | |
[pasteBoard setString:txt forType:NSPasteboardTypeString] | |
} | |
function is_group(layer) { | |
return [layer isMemberOfClass:[MSLayerGroup class]] || [layer isMemberOfClass:[MSArtboardGroup class]] | |
} | |
function process_layer(layer, depth){ | |
log("processing layer " + layer + " at depth " + (depth || 0)) | |
if (depth && INDENT_GROUPS) { | |
layer_tree += strRepeat('\t', depth) | |
} | |
if (COPY_LAYER_TYPE) { | |
layer_tree += [layer class] + ": " | |
} | |
layer_tree += [layer name] | |
layer_tree += "\n" | |
if(is_group(layer) && TRAVERSE_GROUPS){ | |
// we have a group, so go inside it: | |
var sublayers = [[layer layers] array] | |
for (var j = 0; j < [sublayers count]; j++) { | |
process_layer(sublayers[j], depth + 1) | |
} | |
} | |
} | |
for (var i = 0; i < [layers_array count]; i++) { | |
layer = layers_array[i]; | |
process_layer(layer, 0) | |
} | |
copy_text(layer_tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment