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;
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);
}
View SketchLayers.jstalk
/**
* SketchLayers - a collection of layer related functions
*
* @type {object}
*/
var SketchLayers =
{
collection : [],
selection : function()
View browser.jstalk
// handle the browser communication
var browser =
{
name : "",
app : null,
win : null,
tab : null,
/**
* Initialise the browser object
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 )
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" )
{
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;
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: ";
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();
View sketch-loop-selection.jstalk
for( var i = 0; i < selection.length(); i++ )
{
var layer = selection[ i ];
// do something with the selected layer
}