Skip to content

Instantly share code, notes, and snippets.

@romashamin
Last active November 29, 2015 08:36
Show Gist options
  • Save romashamin/82d720e2210b3839d24e to your computer and use it in GitHub Desktop.
Save romashamin/82d720e2210b3839d24e to your computer and use it in GitHub Desktop.
Code snippet to check if `sortLayers` function works properly
// 1. Open Sketch.app and select a number of artboards
// 2. Open Plugins → Custom Plugin... (Ctrl+Shift+K)
// 3. Paste the snippet there and Run
// In the field below you can see the properly sorted list of selected artboards
var doc = context.document
var selection = context.selection
function sortLayers(layers, isAscending) {
var sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:'name'
ascending:isAscending
selector:'localizedStandardCompare:']
return [layers sortedArrayUsingDescriptors:[sortDescriptor]]
}
function getNames(layers) {
var names = []
var loop = layers.objectEnumerator()
while (item = loop.nextObject()) {
var itemName = [item name]
names.push(itemName)
}
return names
}
log(getNames(sortLayers(selection, true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment