Skip to content

Instantly share code, notes, and snippets.

@emalgholzad
Last active June 20, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emalgholzad/b33f2ae848146f3cd7dd44811a66e230 to your computer and use it in GitHub Desktop.
Save emalgholzad/b33f2ae848146f3cd7dd44811a66e230 to your computer and use it in GitHub Desktop.
Sketch plugin development cheat sheet
// NEW API
const sketch = require('sketch');
const document = sketch.getSelectedDocument();
const selection = document.selectedLayers;
const layerSelected = selection.layers[0];
const style = layerSelected.style;
const borders = style.borders;
// OLD API
const doc = context.document;
const page = doc.currentPage();
const selection = context.selection;
const style = selection[0].style();
// sharedDoc
NSDocumentController.sharedDocumentController().currentDocument();
// Example
var sketch = require('sketch')
var document = sketch.getSelectedDocument()
var selectedLayers = document.selectedLayers
var selectedCount = selectedLayers.length
if (selectedCount === 0) {
console.log('No layers are selected.')
} else {
console.log('Selected layers:');
selectedLayers.forEach(function (layer, i) {
console.log((i + 1) + '. ' + layer.name)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment