├── README.md ├── commas.gif ├── new_lines.gif ├── paster.sketchplugin └── Contents │ └── Sketch │ ├── manifest.json │ └── paster.js ├── paster_poster.png ├── spaces.gif ├── table_column.gif └── table_row.gif /README.md: -------------------------------------------------------------------------------- 1 | # Paster — pasting a text data from a clipboard to Sketch text layers. 2 | 3 | ![Paster 2.0](/paster_poster.png) 4 | 5 | ## How it works 6 | 1. Copy some text; 7 | 2. Select text layers in your artboard; 8 | 3. Click a menu item and choose a suitable command. ```Plugin > Paster > [Command]``` 9 | 10 | The Sketch plugin allows pasting a text data from the clipboard to Sketch layers. **As a data separator, you can use commas, spaces, new lines and table cells**. 11 | 12 | ## New lines 13 | ![New lines](/new_lines.gif) 14 | 15 | ## Commas 16 | ![Commas](/commas.gif) 17 | 18 | ## Spaces 19 | ![Spaces](/spaces.gif) 20 | 21 | ## Table row 22 | ![Table](/table_row.gif) 23 | 24 | ## Table column 25 | ![Table](/table_column.gif) 26 | 27 | ## How to install Paster 28 | 1. [Download the zip file with the Paster](https://github.com/Volorf/Paster/archive/master.zip). 29 | 2. Double click on ```paster.sketchplugin``` 30 | 31 | ## Thanks 32 | Great thanks for guys whose send me issues and shared me their ideas about improvements — @illus0r, @richardsison and many other people. It helped me to improve the Paster. 33 | -------------------------------------------------------------------------------- /commas.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/commas.gif -------------------------------------------------------------------------------- /new_lines.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/new_lines.gif -------------------------------------------------------------------------------- /paster.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Paster", 3 | "description": "Multi pasting for Sketch text layers", 4 | "author": "Oleg Frolov", 5 | "authorEmail": "frolololeg@gmail.com", 6 | "homepage": "https://github.com/Volorf/Paster", 7 | "version": 2.0, 8 | "identifier": "com.example.sketch.paster", 9 | "compatibleVersion": 1, 10 | "bundleVersion": 1, 11 | "commands": [ 12 | { 13 | "name": "Commas", 14 | "identifier": "commas", 15 | "shortcut": "ctrl shift 2", 16 | "script": "paster.js", 17 | "handler": "pasteWithCommas" 18 | }, 19 | { 20 | "name": "New lines", 21 | "identifier": "newlines", 22 | "shortcut": "ctrl shift 1", 23 | "script": "paster.js", 24 | "handler": "pasteWithNewLines" 25 | }, 26 | { 27 | "name": "Spaces", 28 | "identifier": "spaces", 29 | "shortcut": "ctrl shift 3", 30 | "script": "paster.js", 31 | "handler": "pasteWithSpaces" 32 | }, 33 | { 34 | "name": "Table row", 35 | "identifier": "tablerow", 36 | "shortcut": "ctrl shift 4", 37 | "script": "paster.js", 38 | "handler": "pasteFromTableRow" 39 | }, 40 | { 41 | "name": "Table column", 42 | "identifier": "tablecolumn", 43 | "shortcut": "ctrl shift 5", 44 | "script": "paster.js", 45 | "handler": "pasteFromTableColumn" 46 | } 47 | ], 48 | "menu": { 49 | "items": [ 50 | "newlines", 51 | "commas", 52 | "spaces", 53 | "tablerow", 54 | "tablecolumn" 55 | ] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /paster.sketchplugin/Contents/Sketch/paster.js: -------------------------------------------------------------------------------- 1 | var commaSeparator = "\u002C"; 2 | var newLineSeparator = "\n"; 3 | var spaceSeparator = "\u0020"; 4 | var tableHorizontalTabSeparator = "\u0009"; 5 | // var tableVerticalTabSeparator = "\u000B"; 6 | var tableVerticalTabSeparator = "\n"; 7 | 8 | // Commas 9 | function pasteWithCommas (context) { 10 | paster(context, commaSeparator); 11 | }; 12 | 13 | // New lines 14 | function pasteWithNewLines (context) { 15 | paster(context, newLineSeparator); 16 | }; 17 | 18 | // Spaces 19 | function pasteWithSpaces (context) { 20 | paster(context, spaceSeparator); 21 | }; 22 | 23 | // Table row 24 | function pasteFromTableRow (context) { 25 | paster(context, tableHorizontalTabSeparator); 26 | }; 27 | 28 | // Table column 29 | function pasteFromTableColumn (context) { 30 | paster(context, tableVerticalTabSeparator); 31 | }; 32 | 33 | 34 | // Main func 35 | function paster (context, separator) { 36 | // 37 | var doc = context.document; 38 | // Get a data from your pasteboard 39 | // doc.showMessage("hi"); 40 | var pasteBoard = NSPasteboard.generalPasteboard(); 41 | // Turn a data in the string type 42 | var stringFromPasteBoard = [pasteBoard stringForType:NSPasteboardTypeString]; 43 | // 44 | var sep = separator; 45 | // Get selected elements from your artboard 46 | var selection = context.selection; 47 | // Define an array length of elements in your artboard 48 | var arrayLength = selection.length; 49 | // Contert a getting string to a JS string 50 | var jsString = String(stringFromPasteBoard); 51 | // How many we meet a separator in your pasteboard data 52 | var countOfSring = jsString.search(sep); 53 | // Create empty array from your pasteboardDara 54 | var arrayFromStringPasteBoard = []; 55 | 56 | // Fill an array with a data from a pasteboard 57 | if (countOfSring <= 0) { 58 | doc.showMessage("Format your text for a right format ☝"); 59 | } else { 60 | // Fill an array 61 | arrayFromStringPasteBoard = jsString.split(sep); 62 | // Populate a pasteboard array with a selected elements array 63 | for (var i = 0; i < arrayLength; i++) { 64 | var layer = selection[i] 65 | layer.stringValue = arrayFromStringPasteBoard[i] 66 | doc.showMessage("Done 👍") 67 | }; 68 | }; 69 | }; 70 | -------------------------------------------------------------------------------- /paster_poster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/paster_poster.png -------------------------------------------------------------------------------- /spaces.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/spaces.gif -------------------------------------------------------------------------------- /table_column.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/table_column.gif -------------------------------------------------------------------------------- /table_row.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Volorf/Paster/b5e50802572ceef7a1748abdf900b019b43299ea/table_row.gif --------------------------------------------------------------------------------