Skip to content

Instantly share code, notes, and snippets.

@tadija
Last active September 14, 2021 13:19
Show Gist options
  • Save tadija/751e7b2e85afa099603b0c49574c0ad9 to your computer and use it in GitHub Desktop.
Save tadija/751e7b2e85afa099603b0c49574c0ad9 to your computer and use it in GitHub Desktop.
Sketch script for exporting artboards to separate .sketch files

sketch-artboards-to-documents

Sketch script for exporting artboards to separate .sketch files

Instructions

  1. Backup your .sketch file, it's going to be destroyed.
  2. Select all artboards you want to export to .sketch files.
  3. Run this script and find your new .sketch files on Desktop.
var sketch = require('sketch')
var Document = require('sketch/dom').Document
var currentDocument = sketch.getSelectedDocument()
var selectedLayers = currentDocument.selectedLayers
if (selectedLayers.length === 0) {
console.log('No layers are selected.')
} else {
selectedLayers.forEach(function (layer, i) {
console.log('Exporting document ' + (i + 1) + '. ' + layer.name)
var newDocument = new Document()
layer.parent = newDocument.selectedPage
newDocument.save('~/Desktop/' + layer.name + '.sketch')
newDocument.close()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment