Skip to content

Instantly share code, notes, and snippets.

View KevinGutowski's full-sized avatar

Kevin Gutowski KevinGutowski

View GitHub Profile
@KevinGutowski
KevinGutowski / readClipboard.js
Created September 9, 2020 00:59
Clipboard/Pasteboard reading
let plainText = 'public.utf8-plain-text'
let html = "public.html"
let customItem = 'com.apple.WebKit.custom-pasteboard-data'
console.log(NSPasteboard.generalPasteboard().pasteboardItems()[0].types())
let pboardItem = NSPasteboard.generalPasteboard().pasteboardItems()[0]
console.log(pboardItem.stringForType(html))
console.log(pboardItem.dataForType(customItem))
@KevinGutowski
KevinGutowski / colorsToLayers.js
Created August 28, 2020 00:10
Sketch Global colors to Layers
let sketch = require('sketch')
let ShapePath = sketch.ShapePath
let Rectangle = sketch.Rectangle
let doc = sketch.getSelectedDocument()
let page = doc.selectedPage
let globalAssets = MSPersistentAssetCollection.sharedGlobalAssets()
let colorAssets = globalAssets.colorAssets()
page.layers = []
@KevinGutowski
KevinGutowski / prefs.js
Created July 23, 2020 18:00
Sketch Prefs
let defaults = NSUserDefaults.standardUserDefaults()
console.log(defaults.dictionaryRepresentation())
@KevinGutowski
KevinGutowski / checkForSFSymbols.js
Created July 22, 2020 05:41
Check for SF Symbols
function checkForSFSymbols() {
let systemVersionPlist = "/System/Library/CoreServices/SystemVersion.plist"
let systemVersionDictionary = NSDictionary.dictionaryWithContentsOfFile(systemVersionPlist)
let systemVersion = systemVersionDictionary.objectForKey("ProductVersion")
let systemVersionArray = systemVersion.split('.').map(stringNumber => parseInt(stringNumber))
if (systemVersionArray[0] >= 10 && systemVersionArray[1] >= 15) {
return true
} else {
return false
@KevinGutowski
KevinGutowski / moveColors.js
Created July 20, 2020 23:19
Move Global Assets Colors and Gradients to Document Asset Colors and Graidents
let globalAssets = MSPersistentAssetCollection.sharedGlobalAssets()
let gColorAssets = globalAssets.colorAssets()
let gGradientAssets = globalAssets.gradientAssets()
let doc = context.document
doc.documentData().assets().setColorAssets(gColorAssets)
doc.documentData().assets().setGradientAssets(gGradientAssets)
@KevinGutowski
KevinGutowski / resetImageFills.js
Created July 14, 2020 08:08
Reset Image Fills
let presetPath = NSBundle.mainBundle().bundlePath() + '/Contents/Resources/assets.sketchpreset';
let presetURL = NSURL.fileURLWithPath(presetPath)
let nativeAssets = MSPersistentAssetCollection.assetCollectionWithURL(presetURL)
let imageCollection = nativeAssets.imageCollection()
let images = nativeAssets.images()
MSPersistentAssetCollection.sharedGlobalAssets().setImages(images)
MSPersistentAssetCollection.sharedGlobalAssets().setImageCollection(imageCollection)
@KevinGutowski
KevinGutowski / inspect.js
Created June 17, 2020 18:28
Internal API Inspection
function dump_obj(obj){
log("#####################################################################################")
log("## Dumping object " + obj )
log("## obj class is: " + [obj className])
log("#####################################################################################")
log("obj.properties:")
log("#####################################################################################")
log([obj class].mocha().properties())
log("obj.propertiesWithAncestors:")
log([obj class].mocha().propertiesWithAncestors())
@KevinGutowski
KevinGutowski / attachModal.js
Last active June 14, 2020 06:23
Attach modal to Sketch document
let window = document.sketchObject.window()
let fiber = coscript.createFiber()
let alert = NSAlert.alloc().init()
alert.addButtonWithTitle("OK")
alert.addButtonWithTitle("Cancel")
alert.setMessageText("This is the message text")
alert.setInformativeText("This is some extra informative text")
alert.setAlertStyle(NSAlertStyleWarning)
@KevinGutowski
KevinGutowski / highlightFirstLetter.js
Last active June 13, 2020 21:58
Attempting to Highlight First Letter
// Create a text layer within an artboard and select the layer to run properly
let Sketch = require('sketch')
let ShapePath = Sketch.ShapePath
let Rectangle = Sketch.Rectangle
// Removes old highlight layer so you can repeatedly run this code
let doc = Sketch.getSelectedDocument()
let oldHighlight = doc.pages[0].layers[0].layers.find(layer => layer.name=="highlight")
if (oldHighlight) { oldHighlight.remove() }
@KevinGutowski
KevinGutowski / NSAttributedStringAttributes
Created June 13, 2020 07:05
NSAttributedString attributes
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let selection = doc.selectedLayers.layers[0]
let menu = NSApplication.sharedApplication().mainMenu()
let pluginsMenu = menu.itemWithTitle('Plugins').submenu()
console.log(pluginsMenu.itemArray()[0].title())
/*
let path = "/Users/Kski/Downloads/file.rtf"
let rtfData = NSData.dataWithContentsOfFile(path)