This file contains 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
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)) |
This file contains 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
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 = [] |
This file contains 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
let defaults = NSUserDefaults.standardUserDefaults() | |
console.log(defaults.dictionaryRepresentation()) |
This file contains 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
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 |
This file contains 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
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) |
This file contains 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
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) |
This file contains 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
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()) |
This file contains 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
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) |
This file contains 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
// 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() } |
This file contains 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
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) |