Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dump the names of all symbols in a Sketch file to an alphabetically sorted text file.
import os
import zipfile
import tempfile
import sys
import json
sketch_doc = sys.argv[1]
def get_symbol_names(zipname):
symbol_names = []
# read the sketch file as a zip file
with zipfile.ZipFile(zipname, 'r') as sketch_file:
for item in sketch_file.infolist():
data =
# find pages and collect symbol names
if item.filename.startswith('pages') and item.filename.endswith('.json'):
parsed_json = json.loads(data)
for layer in parsed_json['layers']:
# only collect names of symbol masters
if layer['_class'] == 'symbolMaster':
sorted_symbol_names = sorted(symbol_names)
# make new file for symbol names
out_name = '%s-symbol-names.txt' % sketch_doc
out = open(out_name, 'w+')
for item in sorted_symbol_names:
line = '%s\r\n' % item
print 'Found %d symbols in the document.' % len(symbol_names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment