Last active
February 1, 2019 08:29
-
-
Save dustinsenos/df14bc33139721fb738d0c0a765bb3cf to your computer and use it in GitHub Desktop.
A simple sketch plugin to rename the selected layers to match the contents of their text.
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 sketch = context.api() | |
var MAX_CHARS = 60 | |
var document = sketch.selectedDocument | |
var selection = document.selectedLayers | |
var renamedTextLayers = false | |
selection.iterate(function(item) { | |
if (!item.isText) { | |
return | |
} | |
if (item.text.length() > MAX_CHARS) { | |
item.name = item.text.substring(0, MAX_CHARS) + "…" | |
} else { | |
item.name = item.text | |
} | |
renamedTextLayers = true | |
}) | |
if (renamedTextLayers) { | |
sketch.message("Layer names now equal the layer’s text content.") | |
} else { | |
sketch.message("Please select a text layer.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To create and run this plugin in Sketch:
Plugin
menu item in SketchCustom Plugin…
Save…
Rename text layers to match contents
Plugin
menu, clickRename text layers to match contents
Tested in Sketch 43.2
Feedback or suggestions welcome @dustin