Last active
April 30, 2024 09:58
-
-
Save abynim/04f88d5e4fe47118bfe3 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
var doc = context.document | |
var selectLayersOfType_inContainer = function(layerType, containerLayer) { | |
// Filter layers using NSPredicate | |
var scope = (typeof containerLayer !== 'undefined') ? [containerLayer children] : [[doc currentPage] children], | |
predicate = NSPredicate.predicateWithFormat("(className == %@)", layerType), | |
layers = [scope filteredArrayUsingPredicate:predicate]; | |
// Deselect current selection | |
[[doc currentPage] deselectAllLayers] | |
// Loop through filtered layers and select them | |
var loop = [layers objectEnumerator], layer; | |
while (layer = [loop nextObject]) { | |
[layer select:true byExpandingSelection:true] | |
} | |
log([layers count] + " " + layerType + "s selected") | |
} | |
// Select all Artboards in current page | |
selectLayersOfType_inContainer("MSArtboardGroup") | |
// Select all Text Layers in current page | |
//selectLayersOfType_inContainer("MSTextLayer") | |
// Types of layers that can be selected : | |
// MSLayerGroup | |
// MSShapeGroup | |
// MSShapePathLayer | |
// MSTextLayer | |
// MSArtboardGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, the command seems to not working anymore.
Here is my result "TypeError: doc. currentPage(). deselectAllLayers is not a function. (In 'doc. currentPage(). deselectAllLayers()', 'doc. currentPage(). deselectAllLayers' is undefined)
at selectLayersOfType_inContainer (/Users/A987SK/Library/Application Support/com.bohemiancoding.sketch3/Plugins/Untitled.sketchplugin:12:39)
at onRun (/Users/A987SK/Library/Application Support/com.bohemiancoding.sketch3/Plugins/Untitled.sketchplugin:23:31)
Script executed in 0.027800s"
does anyone have a solution ?
Thanks