This file contains 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
// run this code in Sketch's script window (Plugins > Run Script...) | |
// tested in Sketch 57 | |
context.document.currentPage().changeSelectionBySelectingLayers(nil); | |
let children = context.document.currentPage().children().objectEnumerator(), layer; | |
while(layer = children.nextObject()) { | |
layer.select_byExtendingSelection(context.document.sidebarController().filterViewController().filter().shouldIncludeNode(layer), true); | |
} |
This file contains 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
// Name of layer to copy | |
var sourceLayerName = "gray_rectangle" | |
// Ask user to select a Sketch file: | |
var openDialog = NSOpenPanel.openPanel() | |
openDialog.setCanChooseFiles(true) | |
openDialog.setAllowedFileTypes(["sketch"]) | |
openDialog.setCanChooseDirectories(false) | |
openDialog.setAllowsMultipleSelection(false) | |
openDialog.setCanCreateDirectories(false) |
This file contains 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 |
This file contains 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 writeTextToFile = function(text, filePath) { | |
var t = [NSString stringWithFormat:@"%@", text], | |
f = [NSString stringWithFormat:@"%@", filePath]; | |
return [t writeToFile:f atomically:true encoding:NSUTF8StringEncoding error:nil]; | |
} | |
var readTextFromFile = function(filePath) { | |
var fileManager = [NSFileManager defaultManager]; | |
if([fileManager fileExistsAtPath:filePath]) { | |
return [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; |