How does JSTalk (the language) work?
NSString *someContent = @"Hello World!";
NSString *path = @"/tmp/foo.txt";
[[someContent dataUsingEncoding:NSUTF8StringEncoding] writeToFile:path atomically:YES];
And here is how it would normally look in a bridged scripting language:
var someContent = NSString.stringWithString_("Hello World!")
var path = "/tmp/foo.txt"
This is a valid script in JSTalk, but it doesn't look very nice. For instance, there are lots of underscores in the method names, and you don't get the nested message passing like you do in Objective-C. To fix this quandary, JSTalk adds a light preprocessor which will allow you to use Objective-C message syntax like so:
var someContent = @"Hello World!"
var path = @"/tmp/foo.txt"
[[someContent dataUsingEncoding:NSUTF8StringEncoding] writeToFile:path atomically:true]
Give me an example
Here's an AppleScript example, for adding a new rectangle object to a sketch document:
tell application "Sketch"
tell document 1
set o to make new box
set width of o to 100
set height of o to 100
set stroke thickness of o to 10
And here's how you do it with JSTalk, using a doctored version of Sketch (6 lines of code, + the JSTalk framework):
var sketch = [JSTalk application:"Sketch"];
var doc = [sketch orderedDocuments]
var rectangle = [doc makeNewBox];
If you aren't a fan of the optional bracket syntax, you can also write the script this way:
var sketch = JSTalk.application_("Sketch");
var doc = sketch.orderedDocuments()
var rectangle = doc.makeNewBox();
But no apps out there currently support JSTalk!
Applications can also be scripted using Cocoa's Script Bridge class, SBApplication. Here's an example:
[[SBApplication application:"iChat"] setStatusMessage:"Happy (funball)"];
Although this is great to have, it's not the same as an application natively support JSTalk over DO. Anything more than simple tasks using SBApplication tends to be a little more than difficult.
Aka, loadable bundles which add functionality to JSTalk, via helper classes, wrappers, and categories.
JSTalk comes with some standard helper categories (which you can currently find in JSTalkExtras.m), but it will also look in your ~/Library/Application Support/JSTalk/Plug-ins/ folder, and load any .jstplugin bundles it sees. You can turn this off in your application if you don't like that idea, via [JSTalk setShouldLoadJSTPlugins:NO];
There are two examples with JSTalk, one that just adds a category cocoa's string class: - [NSString reversedString]. The other example is "FMDB.jstplugin", which loads the FMDB SQLite classes, for use in JSTalk. This allows you to use sqlite to create, insert, update, etc, sql tables from JSTalk.
But it doesn't do X:
Let us know by sending an email to firstname.lastname@example.org
If you're a programmer, you're going to want to visit the git repository: http://github.com/ccgus/jstalk/tree/master.
Mailing list and bug reporting:
- Developer mailing list: http://groups.google.com/group/jstalk-dev
- Bug reporting: http://jstalk.lighthouseapp.com/projects/26692-jstalk/
As said earlier, JSTalk is a blend of existing technologies, and has very little original code in it. Here's what it uses:
- JSTalk Icon, created by Brad Ellis.
- TDParseKit, from Todd Ditchendorf.
- NoodleLineNumberView, from Paul Kim / Noodlesoft.
- TextExtras, from Mike Ferris.