Skip to content

Instantly share code, notes, and snippets.

@getflourish
getflourish / Sketch-to-FramerJS-Boilerplate
Created October 17, 2014 08:50
This plugin copies FramerJS boiler plate code for the currently selected layer.
// (shift cmd c)
// This plugin copies FramerJS boiler plate code for the currently selected layer.
// Example:
/*
# Import Table Cell from Sketch
tableCell = layers.Table_Cell
// get text styles
var text_styles_library = doc.documentData().layerTextStyles().objectsSortedByName();
// apply the style to the selected text layer
selection[0].setStyle(text_styles_library[0]);
// => Result: [MSSharedLayerStyle reflection]: unrecognized selector sent to instance
var request = require('request'),
query = require('querystring'),
args = require('optimist').
options('key', { alias: 'k' }).
options('secret', { alias: 's' }).
options('signature', { alias: 'm', default: "HMAC-SHA1" }).
argv;
var options = {
url: 'https://secure.splitwise.com/api/v3.0/get_request_token',
@getflourish
getflourish / speaker.js
Last active August 29, 2015 14:17 — forked from jeffehobbs/speaker.js
Bookmarklet to scrub and speak current URL via SpeechSynthesisUtterance. (Please use your own Readability API token). Added chunking.
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"2.0.3",function($,L){
// speak current webpage
// jhobbs 2013
// chunking by getflourish 2015
function stop(){
speechSynthesis.cancel();
@getflourish
getflourish / Select below selection.js
Last active August 29, 2015 14:18
Select below selection.sketchplugin
// (cmd shift b)
// set the scope to the layer group that the currently selected layer is in
var scope = selection[0].parentGroup().layers().array();
// calculate the bottom position of the selected layer
var bottom = selection[0].absoluteRect().y() + selection[0].absoluteRect().height();
// set up the predicate and receive an array of matched layers
var predicate = NSPredicate.predicateWithFormat("absoluteRect.y > %@", bottom);
var doc = context.document;
var layer = context.selection[0]
var style = layer.style().textStyle()
var scope = context.document.currentPage().children();
selectLayersByTextStyle(style, scope)
function selectLayersByTextStyle(textStyle, scope) {
var predicate = NSPredicate.predicateWithFormat("(style.textStyle != NULL) && (style.textStyle isEqualForSync:%@)", textStyle);
var textStyle = context.selection[0].style().textStyle();
var predicate = NSPredicate.predicateWithFormat("(style.textStyle != nil) && [style.textStyle isEqualForSync:%@ asPartOfSymbol:nil]", textStyle);
context.document.currentPage().children().filteredArrayUsingPredicate(predicate);
// error: Unable to parse the format string "(style.textStyle != nil) && [style.textStyle isEqualForSync:%@ asPartOfSymbol:nil]"
{
"Menu": {
"statusbar-time": "12:30",
"profile-email": "heyfromjonathan@gmail.com",
"label-forums": "Forums",
"label-updates": "Updates",
"label-promos": "Promos",
"label-purchases": "Purchases",
"label-social": "Social",
"label-spam": "Spam",
@getflourish
getflourish / gist:f86ecf58d427c81f99d3
Created May 29, 2015 17:14
replace partial in sketch layer selection
for (var i = 0; i < context.selection.count(); i++) {
var layer = context.selection[i];
var name = layer.name();
layer.setName(name.replace("Schwarz", "Orange"));
}
@getflourish
getflourish / create incremental numbers
Last active August 29, 2015 14:22
Random char generator
for (var i = 0; i < context.selection.count(); i++) {
var layer = context.selection[i];
var textLayer = layer.children().objectAtIndex(0)
var char = "" + i;
textLayer.setStringValue(char)
}