├── Grid Master.sketchplugin └── Contents │ └── Sketch │ ├── shared.js │ ├── manifest.json │ └── toggle.js └── README.md /Grid Master.sketchplugin/Contents/Sketch/shared.js: -------------------------------------------------------------------------------- 1 | // Check if selected layer is an artboard 2 | function artboardOf(layer) { 3 | if (layer.isMemberOfClass(MSArtboardGroup)) { 4 | return layer 5 | } else { 6 | return layer.parentArtboard() 7 | } 8 | } 9 | 10 | // Returns grid or layout objects for target artboard if assigned 11 | function targetOf(artboard, isLayout) { 12 | return isLayout ? artboard.layout() : artboard.grid() 13 | } 14 | -------------------------------------------------------------------------------- /Grid Master.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Vyacheslav Dubovitsky", 3 | "commands" : [ 4 | { 5 | "script" : "toggle.js", 6 | "name" : "Toggle Grid", 7 | "shortcut" : "ctrl g", 8 | "handler" : "toggleGridOnSelection", 9 | "identifier" : "com.exevil.grid-master.toggleGridOnSelection" 10 | }, 11 | { 12 | "script" : "toggle.js", 13 | "name" : "Toggle Layout", 14 | "shortcut" : "ctrl b", 15 | "handler" : "toggleLayoutOnSelection", 16 | "identifier" : "com.exevil.grid-master.toggleLayoutOnSelection" 17 | }, 18 | { 19 | "script" : "toggle.js", 20 | "name" : "Toggle Grid on All Artboards", 21 | "shortcut" : "ctrl shift g", 22 | "handler" : "toggleGridOnAllArtboards", 23 | "identifier" : "com.exevil.grid-master.toggleGridOnAllArtboards" 24 | }, 25 | { 26 | "script" : "toggle.js", 27 | "name" : "Toggle Layout on All Artboards", 28 | "shortcut" : "ctrl shift b", 29 | "handler" : "toggleLayoutOnAllArtboards", 30 | "identifier" : "com.exevil.grid-master.toggleLayoutOnAllArtboards" 31 | } 32 | ], 33 | "menu" : { 34 | "title" : "Grid Master", 35 | "items" : [ 36 | "com.exevil.grid-master.toggleGridOnSelection", 37 | "com.exevil.grid-master.toggleLayoutOnSelection", 38 | "-", 39 | "com.exevil.grid-master.toggleGridOnAllArtboards", 40 | "com.exevil.grid-master.toggleLayoutOnAllArtboards" 41 | ] 42 | }, 43 | "identifier" : "com.exevil.grid-master", 44 | "version" : "1.3", 45 | "description" : "Plugin that makes toggling visibility of grid and layout for multiple artboards real", 46 | "authorEmail" : "m@dbv.ae", 47 | "name" : "Grid Master", 48 | "appcast" : "https://api.sketchpacks.com/v1/plugins/com.exevil.grid-master/appcast" 49 | } 50 | -------------------------------------------------------------------------------- /Grid Master.sketchplugin/Contents/Sketch/toggle.js: -------------------------------------------------------------------------------- 1 | @import "shared.js" 2 | 3 | // Handlers 4 | 5 | // on Selection 6 | var toggleGridOnSelection = function(context) { 7 | var selection = context.selection 8 | var isLayout = false 9 | toggle(selection, isLayout) 10 | } 11 | 12 | var toggleLayoutOnSelection = function(context) { 13 | var selection = context.selection 14 | var isLayout = true 15 | toggle(selection, isLayout) 16 | } 17 | 18 | // on All 19 | var toggleGridOnAllArtboards = function(context) { 20 | var artboards = context.document.artboards() 21 | var isLayout = false 22 | toggle(artboards, isLayout) 23 | } 24 | 25 | var toggleLayoutOnAllArtboards = function(context) { 26 | var artboards = context.document.artboards() 27 | var isLayout = true 28 | toggle(artboards, isLayout) 29 | } 30 | 31 | // Functions 32 | 33 | function toggle(layers, isLayout) { 34 | 35 | // Check that any layers given 36 | if (!layers.count) { 37 | document.showMessage("No layers selected") 38 | return 39 | } 40 | 41 | var newValue 42 | 43 | var loop = layers.objectEnumerator() 44 | while (item = loop.nextObject()) { 45 | 46 | // If selected layer neither artboard nor artboard child, skip 47 | if (artboardOf(item)) { 48 | item = artboardOf(item) 49 | } else { 50 | continue 51 | } 52 | 53 | // Access item grid or layout objects if assigned 54 | var target = targetOf(item, isLayout) 55 | 56 | // Use grid visiblity value of first given aartboard to create an initial value 57 | if (newValue == nil) { 58 | // If target loaded already, inverse value. Otherwise set true because target newer been presented before. 59 | newValue = target ? !target.isEnabled() : true 60 | } 61 | 62 | // Check if artboard have grid or layout and applying a default one if not 63 | if (!target) { 64 | isLayout ? item.layout = MSDefaultLayoutGrid.defaultLayout() : item.grid = MSDefaultGrid.defaultGrid() 65 | } 66 | 67 | target.setIsEnabled(newValue) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sketch Grid Master 2 | Grid Master is a Sketch plugin that fixes long-standing bugs and adds new functionaity related on work with Grid and Layout. 3 | 4 | ## Features 5 | **Toggle Grid/Layout** — fixes the long-standing bug with toggling grid and layout visibility for multiple artboards. Please check the [installation guide](https://github.com/exevil/sketch-grid-master#installation) to make it work as expected. 6 | 7 | ![Toggle Grid/Layout](http://i.dbv.ae/gxZV/1.gif) 8 | 9 | **Toggle Grid/Layout on All Artboards** — toggles Grid/Layout on all Artboards on current page via single command. 10 | 11 | ![Toggle Grid/Layout on All Artboards](http://i.dbv.ae/gyRZ/2.gif) 12 | 13 | ~~**Grid/Layout Settings for All Artboards...** — opens regular Grid/Layout Settings dialog which affects all artobards on current page.~~ _Deprecated since Sketch added the same functionality._ 14 | 15 | ## Installation 16 | [![Install Grid Master with Sketchpacks](http://sketchpacks-com.s3.amazonaws.com/assets/badges/sketchpacks-badge-install.png "Install Grid Master with Sketchpacks")](https://sketchpacks.com/exevil/sketch-grid-master/install) 17 | 18 | Since grid or layout visibility toggling are the most common functions in design workflow I used regular `CTRL + G` & `CTRL + L` shortcuts for these plugin commands. To make it work as expected you should assign any different shortcut to Sketch's default Show Grid and Show Layout functions. Here're 4 easy steps how to do it: 19 | 20 | 1. [Download](https://github.com/exevil/sketch-grid-master/archive/master.zip) and install Sketch Grid Master as any usual plugin by click on it; 21 | 2. Open  → System Preferences → Keyboard → Shortcuts → App Shortcuts and hit the + button; 22 | 3. Choose Sketch.app as Application, enter "Show Grid" as Menu Title and assign `CTRL+ALT+G` as Keyboard Shortcut; 23 | 4. Repeat step 3 with "Show Layout" as Menu Title and `CTRL+ALT+L` as Keyboard Shortcut. 24 | 25 | Voila! Now you can use familiar shortcuts with new functionality. 26 | 27 | ## Feedback 28 | Your feedback is always appreciated. You can [Create an Issue](https://github.com/exevil/sketch-grid-master/issues/new) to report errors and feature requests or drop me a line directly to [m@dbv.ae](mailto:m@dbv.ae?Subject=Sketch%20Grid%20Master%20Feedback) 29 | 30 | ## Donation 31 | Even a small donation from your side is important. This is really motivating to see that people want to pay for your work. 32 | 33 | [![](https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=evil%2emrfix%40gmail%2ecom&lc=GB&item_name=Sketch%20Plugin%20Donation&item_number=sketch%2dplugin¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) 34 | --------------------------------------------------------------------------------