Skip to content

Instantly share code, notes, and snippets.

@uhunkler
uhunkler / sketch-create-table-01.jstalk
Created May 21, 2014
A basic table creation plugin.
View sketch-create-table-01.jstalk
/*global JSTalk:false, NSApplication:false, NSAlert:false, print:true */
// Set the basic variables for an externally run script
// which are set by default when the script is run
// as a plugin from within Sketch. "doc" is defined when the script
// is called from within Sketch.
if (doc === undefined) {
var doc, selection;
}
var sketch = null;
@uhunkler
uhunkler / sketch-empty-selection-bug.jstalk
Last active Aug 29, 2015
Empty selection bug - Sketch 2.4.3 - OS X 10.9.2
View sketch-empty-selection-bug.jstalk
doc.showMessage('sel: ' + selection.length());
log(selection.length());
for (var i = 0; i < selection.length(); i++)
{
var layer = selection[i];
log(layer);
}
@uhunkler
uhunkler / SketchLayers.jstalk
Last active Sep 12, 2016
SketchLayers - JSTalk Sketch
View SketchLayers.jstalk
/**
* SketchLayers - a collection of layer related functions
*
* @type {object}
*/
var SketchLayers =
{
collection : [],
selection : function()
@uhunkler
uhunkler / browser.jstalk
Created Apr 27, 2013
browser communication object - JSTalk
View browser.jstalk
// handle the browser communication
var browser =
{
name : "",
app : null,
win : null,
tab : null,
/**
* Initialise the browser object
@uhunkler
uhunkler / doJavaScript.jstalk
Last active Dec 16, 2015
doJavaScript - JSTalk browser
View doJavaScript.jstalk
/**
* Execute JavaScript in the browser
*
* @param {string} js JavaScript string
* @required {object} browsername the browser name
* @required {object} browser the reference to the browser
* @required {object} tab the reference to the active tab
* @return {mixed} return value from JavaScript
*/
function doJavaScript( js )
@uhunkler
uhunkler / browserConnection.jstalk
Created Apr 27, 2013
browser connection - JSTalk
View browserConnection.jstalk
// create the connection to the browser
var browsername = "Safari",
// var browsername = "Google Chrome",
browser = SBApplication.application( browsername ),
win = browser.windows()[0],
tab = null;
// get the active tab
if( browsername === "Safari" || browsername === "WebKit" )
{
@uhunkler
uhunkler / readTextFromFile.jstalk
Last active Oct 4, 2016
read and write TextToFile - JSTalk Sketch
View readTextFromFile.jstalk
/**
* Read text from a file at the given path
*
* @param {string} path given file path
* @return {mixed} string with text if successful, false if error
*/
function readTextFromFile( path )
{
var result = false;
@uhunkler
uhunkler / simple-test-object.jstalk
Created Apr 26, 2013
test object - JSTalk Sketch
View simple-test-object.jstalk
/**
* Test object for simple asserts
* test.assert( typeof 1 === 'number', '1 is a number' ); // add a test
* test.print( 'text' ); // add some text
* test.show(); // output all results
*/
var test = {
heap: [],
assert: function (value, desc) {
var result = value ? "--- pass: " : "xxx fail: ";
@uhunkler
uhunkler / clipboard-test.jstalk
Last active Aug 23, 2017
clipboard handling in JSTalk for Sketch
View clipboard-test.jstalk
// @requires https://gist.github.com/uhunkler/5465857
var text = 'to clipboard ' + new Date(),
returnedtext = '';
clipboard.set( text );
returnedtext = clipboard.get();
test.assert( text === returnedtext, 'Text correctly copied and read to/from the clipboard' );
test.show();
@uhunkler
uhunkler / sketch-loop-selection.jstalk
Created Apr 13, 2013
loop selection - JSTalk Sketch
View sketch-loop-selection.jstalk
for( var i = 0; i < selection.length(); i++ )
{
var layer = selection[ i ];
// do something with the selected layer
}
You can’t perform that action at this time.