This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc.showMessage('sel: ' + selection.length()); | |
log(selection.length()); | |
for (var i = 0; i < selection.length(); i++) | |
{ | |
var layer = selection[i]; | |
log(layer); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* SketchLayers - a collection of layer related functions | |
* | |
* @type {object} | |
*/ | |
var SketchLayers = | |
{ | |
collection : [], | |
selection : function() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handle the browser communication | |
var browser = | |
{ | |
name : "", | |
app : null, | |
win : null, | |
tab : null, | |
/** | |
* Initialise the browser object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" ) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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: "; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for( var i = 0; i < selection.length(); i++ ) | |
{ | |
var layer = selection[ i ]; | |
// do something with the selected layer | |
} |
NewerOlder