Last active
March 27, 2016 06:56
-
-
Save davyzhang/2ddec06f746be33c3ed3 to your computer and use it in GitHub Desktop.
sketchapp plugin script to export document color as css rgba value
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 doc = context.document; | |
var app = NSApplication.sharedApplication(); | |
var appController = app.delegate(); | |
var colors = doc.documentData().assets().primitiveColors(); | |
// Convert MSArray into array | |
var mspalette = colors.array(); | |
// Convert MSColors into hex strings | |
var palette = []; | |
for (var i = 0; i < mspalette.count(); i++) { | |
var color = mspalette[i]; | |
var value = 'rgba(' + Math.round(color.red() * 255) + ',' + | |
Math.round(color.green() * 255) + ',' + | |
Math.round(color.blue() * 255) + ',' + | |
Math.round(color.alpha() * 100)/100 + ');'); | |
log(value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment