Skip to content

Instantly share code, notes, and snippets.

💎
Cookin up some Sketch plugins

Kevin Gutowski KevinGutowski

💎
Cookin up some Sketch plugins
Block or report user

Report or block KevinGutowski

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View minimap.js
framework("QuartzCore")
var panelWidth = 300
var panelHeight = 200
let panel = NSPanel.alloc().init()
panel.setFrame_display(NSMakeRect(0, 0, panelWidth, panelHeight), true)
panel.setStyleMask(NSWindowStyleMaskHUDWindow
| NSTitledWindowMask | NSClosableWindowMask)
panel.title = "Testing"
@KevinGutowski
KevinGutowski / stack.js
Last active Sep 17, 2019
Stack view example
View stack.js
let threadDictionary = NSThread.mainThread().threadDictionary()
let panelID = "com.testPanel"
if (threadDictionary[panelID]) {
let panel = threadDictionary[panelID]
panel.close()
threadDictionary.removeObjectForKey(panelID)
}
var panelWidth = 312
var panelHeight = 210
let panel = NSPanel.alloc().init()
@KevinGutowski
KevinGutowski / sheet.js
Last active Sep 13, 2019
Trigger a Sheet alert
View sheet.js
let sketch = require('sketch')
let document = sketch.getSelectedDocument()
let documentWindow = document.sketchObject.windowControllers()[0].window())
let mySheetWindow = NSWindow.alloc().initWithContentRect_styleMask_backing_defer(
NSMakeRect(0, 0, 200, 100),
(NSWindowStyleMaskTitled | NSWindowStyleMaskDocModalWindow),
NSBackingStoreBuffered,
true
)
View Callback-HSMain.m
//
// HSMain.m
// HelloSketch
//
// Created by Kevin Gutowski on 8/17/19.
// Copyright © 2019 Kevin. All rights reserved.
//
#import "HSMain.h"
@import AppKit;
@KevinGutowski
KevinGutowski / Load Preview.js
Last active Aug 21, 2019
Replicating Sketch's Preview window
View Load Preview.js
let previewWindow = NSApplication.sharedApplication().windows().find(window => window.title() == 'Preview')
let webview = previewWindow.contentView().subviews()[1] // need to launch sketch preview in order to find the proper webview and to start up the sketch server
let threadDictionary = NSThread.mainThread().threadDictionary()
let panelID = "com.testPanel"
if (threadDictionary[panelID]) {
let panel = threadDictionary[panelID]
panel.close()
threadDictionary.removeObjectForKey(panelID)
@KevinGutowski
KevinGutowski / HSMain.m
Last active Aug 17, 2019
Loading a XIB file in a Sketch plugin
View HSMain.m
#import "HSMain.h"
@import AppKit;
@implementation HSMain
- (NSString *)helloText {
NSLog(@"HelloSketch (Sketch Plugin)");
return @"Hiya, sending singal from HSMain";
}
@KevinGutowski
KevinGutowski / export_without_rubric.py
Created Aug 12, 2019
Gradescope: Remove rubric cover pages from Export Submissions
View export_without_rubric.py
#!/usr/bin/env python
'''
usage: export_without_rubric.py export_folder output_folder num_rubric_pages
eg. export_without_rubric.py assignment_4183_export output_pdfs 1
'''
import sys
import os
import glob
@KevinGutowski
KevinGutowski / actions.js
Last active Jul 30, 2019
Triggering an action in Sketch
View actions.js
// Example
// Thanks to Aby for the idea / inital code nippet
// https://sketchplugins.com/d/201-inserting-a-layer-into-a-document-with-sketch-ux/7
context.document.actionsController().actionForID("MSShowReplaceColorSheetAction").performAction(nil);
// there may be cases where you need to pass in a reference to an object in order for the for the action to work
// here is how you can insert a symbol instance programmatically
// for now let's assume you have a symbol master selected
@KevinGutowski
KevinGutowski / menus.js
Created Jul 19, 2019
Toggling Sketch menu items
View menus.js
let menu = NSApplication.sharedApplication().mainMenu()
let pluginsMenu = menu.itemWithTitle('Plugins').submenu()
let baseAlignPluginMenuItem = pluginsMenu.itemWithTitle('BaseAlign'))
baseAlignPluginMenuItem.setEnabled(false)
baseAlignPluginMenuItem.setState(true)
@KevinGutowski
KevinGutowski / notification.js
Created Jul 19, 2019
Create a notification within a sketch plugin
View notification.js
let notification = NSUserNotification.alloc().init()
let randomNumber = Math.random()
notification.setIdentifier("com.kevin.testNotification" + randomNumber)
notification.setTitle("Hi there")
notification.setSubtitle("What about this?")
notification.setInformativeText("Your symbol")
notification.setSoundName = NSUserNotificationDefaultSoundName
let notificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
notificationCenter.deliverNotification(notification)
You can’t perform that action at this time.