├── Copy SCSS Colors.sketchplugin └── Contents │ └── Sketch │ ├── manifest.json │ └── script.cocoascript ├── OLD-Copy SCSS Colors.sketchplugin └── README.md /Copy SCSS Colors.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "Copy SCSS Colors", 3 | "description" : "Copt SCSS color variable declarations to your clipboard from a selection of color shape objects", 4 | "author" : "iain eudailey", 5 | "identifier" : "com.example.sketch.53bfd550-238f-46b6-8b3b-8373105d6acc", 6 | "version" : "2.0", 7 | "homepage" : "http://github.com/graphical-iain/Copy-SCSS-Colors", 8 | "commands" : [ 9 | { 10 | "script" : "script.cocoascript", 11 | "name" : "Copy SCSS Colors", 12 | "shortcut": "cmd shift c", 13 | "handlers" : { 14 | "run" : "onRun" 15 | }, 16 | "identifier" : "copy-colors" 17 | } 18 | ], 19 | "menu" : { 20 | "items" : [ 21 | "copy-colors" 22 | ], 23 | "title" : "Copy SCSS Colors" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Copy SCSS Colors.sketchplugin/Contents/Sketch/script.cocoascript: -------------------------------------------------------------------------------- 1 | var onRun = function(context) { 2 | 3 | var scssVars = ""; 4 | 5 | // store the pasteboard object 6 | var clipboard = { 7 | pasteBoard : null, 8 | init : function() { 9 | // save the pasteboard object 10 | this.pasteBoard = NSPasteboard.generalPasteboard(); 11 | }, 12 | set : function( text ) { 13 | // set the clipboard to the given text 14 | if( typeof text === 'undefined' ) return null; 15 | 16 | if( !this.pasteBoard ) { 17 | this.init(); 18 | } 19 | 20 | this.pasteBoard.declareTypes_owner( [ NSPasteboardTypeString ], null ); 21 | this.pasteBoard.setString_forType( text, NSPasteboardTypeString ); 22 | 23 | return true; 24 | } 25 | }; 26 | 27 | 28 | //returns background color as scss varable delaration: 29 | // $c-["layer name"]: #["hex"]; 30 | // ( eg. $c-red: #ff0000; ) 31 | var getBackground = function getBackground(layer){ 32 | 33 | 34 | if ( layer.class() == MSShapeGroup && layer.style().fills().count() > 0 ) { 35 | var color = layer.style().fills().firstObject().color().immutableModelObject().hexValue().toLowerCase(); 36 | var name = layer.name().toLowerCase().replace(" ", "-"); 37 | 38 | log(color); 39 | return "\n$c-" + name + ": #" + color + ";"; 40 | 41 | } else { 42 | return ""; 43 | } 44 | }; 45 | 46 | 47 | 48 | var selection = context.selection; 49 | 50 | for ( var i=0; i