Skip to content

Instantly share code, notes, and snippets.

@janily
Created May 6, 2021 02:25
Show Gist options
  • Save janily/8df4b779fe90d93240cb6ee7e10b8204 to your computer and use it in GitHub Desktop.
Save janily/8df4b779fe90d93240cb6ee7e10b8204 to your computer and use it in GitHub Desktop.
get libaray props
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let libraries = sketch.getLibraries()
let textStyles = doc.sharedTextStyles
//var importedStyles = []
//var textStyleRefs = libraries.getImportableTextStyleReferencesForDocument(doc)
//textStyleRefs.forEach( ref => importedStyles.push(ref.import()))
let option = []
libraries.forEach(item => {
option.push(item.name)
})
//console.log(option)
let myLibrary = libraries.find(library => library.name == 'TeaUI 腾讯云控制台组件库')
let swatchRefs = myLibrary.getImportableSwatchReferencesForDocument(doc)
let styleLibrary = libraries.find(library => library.name == 'TeaUI 腾讯云控制台组件库')
//console.log(styleLibrary)
let styleRefs = styleLibrary.getImportableTextStyleReferencesForDocument(doc)
//console.log(styleRefs)
styleRefs.forEach(style => {
//console.log(style.import().style.fontSize)
})
const options = []
const tokens = swatchRefs.map(swatch => {
return {
name: swatch.import().name,
value: swatch.import().color
}
})
//console.log(tokens)
let variables = {}
tokens.forEach(item => {
let layerNameArr = item.name.split('/');
let value = item.value;
console.log(value)
})
console.log(tokens)
let document = sketch.getSelectedDocument()
let overrideTextField = document.sketchObject.inspectorController().currentController().stackView().sectionViews()[3].subviews()[6].subviews()[0].subviews()[0].subviews()[0].subviews()[0].viewAtColumn(0).subviews()[0].subviews()[0].subviews()[1] //be sure to select a symbol with a text override as the first override
// 🙀
let text = overrideTextField.stringValue()
let selectedRange = overrideTextField.currentEditor().selectedRange()
let selectedText = text.slice(selectedRange.location, selectedRange.location + selectedRange.length)
console.log(selectedText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment