Skip to content
Newer
Older
100644 209 lines (144 sloc) 8.13 KB
49ee971 @ccgus Now there's a website and stuff. How awesome is that?
authored Sep 12, 2009
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <title>JSTalk</title>
7
8 <style type="text/css">
9
10 body {
11 background-color: #eee;
12 margin: 0;
13 padding: 0px;
14 font-family: "Lucida Grande", Verdana, Arial, sans-serif;
15 }
16
17 #mainBack {
18 margin: 0 auto;
19 position: relative;
20 background-color: #fff;
21 width: 800px;
22 }
23
24 #main {
25 border-right: 1px solid #aaa;
26 border-left: 1px solid #aaa;
27 background-color: #fff;
28 padding-top: 30px;
29 }
30
31 .headList {
32 padding-top: 5px;
33 padding-left: 20px;
34 color: #444;
35 font-size: 11px;
36 }
37
38 .headList b {
39 padding-bottom: 5px;
40 color: #000;
41 }
42 .headList a {
43 text-decoration: none;
44 color: #444;
45 }
46
47 .headList a:hover {
48 text-decoration: underline;
49 color: blue;
50 }
51
52 .codeSample {
53 background-color: #eee;
54 }
55
56 </style>
57
58 </head>
59
60 <body>
61
62 <div id="mainBack" style="border-top: 0px;">
63
64 <div id="main">
65 <center>
66 <img src="images/jstalk-banner.png" alt="JSTalk" /><br/>
67
68 </center>
69
70 </center>
71
72 <div style="padding: 40px; padding-top: 10px;">
73
74 <table border="0">
75 <tr>
76 <td valign="middle" style="width: 58px;">
77 <a href="/download/JSTalkPreview.zip"><img src="images/jstalkdisk.png" alt="Download JSTalk" width="58" height="77" border="0"></a>
78 </td>
79 <td class="headList" align="left">
80
81 <a href="/download/JSTalkPreview.zip" style="color: black; font-weight: bold; text-decoration: underline;">Free download, version 1.0b</a><br/>
82 Requires Mac OS X 10.5 or later, works great on 10.6.<br/>
83 </td>
84 </tr>
85 </table>
86
87 <center>
88 <img src="images/sepbar.png" alt="this is a separator" />
89 </center>
90 <br/>
91 JSTalk is a scripting language built on top of JavaScript, with a bridge to Apple's Cocoa libraries. You can use it to communicate with other applications just like AppleScript does, but without the AppleScript.<br/><br/>
92
93 If you're a programmer, you're going to want to visit the git repository: <a href="http://github.com/ccgus/jstalk/tree/master">http://github.com/ccgus/jstalk/tree/master</a>.<br/>
94 If you just want to use JSTalk, you'll want to download the JSTalk Editor, and samples: <a href="http://www.flyingmeat.com/download/latest/JSTalkPreview.zip">JSTalkPreview.zip</a><br/><br/>
95
96 <strong>How does JSTalk (the language) work?</strong><br/>
97
98 JSTalk is built on top of Apple's JavaScriptCore, the same JavaScript engine that powers Safari. So when you write in JSTalk, you are really writing JavaScript.<br/><br/>
99
100 JSTalk also includes a bridge which lets you access Apple's Cocoa frameworks from JavaScript. This means you have a ton wonderful classes and functions you can use in addition to the standard JavaScript library.<br/><br/>
101
102 JSTalk also adds a preprocessor to make using the Cocoa frameworks friendlier. Since Cocoa is written in Objective-C, you get a different syntax than what you'd normally encounter in JavaScript for calling methods. For example, here's some typical Cocoa code for writing a string to a file:<br/>
103
104 <pre style="background-color: #eee;">NSString *someContent = @"Hello World!";
105 NSString *path = @"/tmp/foo.txt";
106 [[someContent dataUsingEncoding:NSUTF8StringEncoding] writeToFile:path atomically:YES];</pre>
107
108 And here is how it would normally look in a bridged scripting language:
109
110 <pre style="background-color: #eee;">var someContent = NSString.stringWithString_("Hello World!")
111 var path = "/tmp/foo.txt"
112 someContent.dataUsingEncoding_(NSUTF8StringEncoding).writeToFile_atomically_(path, true)</pre>
113
114 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:
115
116 <pre style="background-color: #eee;">var someContent = @"Hello World!"
117 var path = @"/tmp/foo.txt"
118 [[someContent dataUsingEncoding:NSUTF8StringEncoding] writeToFile:path atomically:true]</pre>
119 <br/>
120
121
122 <strong>Give me an example</strong><br/>
123
124 Here's an AppleScript example, for adding a new rectangle object to a sketch document:
125
126 <pre class="codeSample">tell application "Sketch"
127 tell document 1
128 set o to make new box
129 set width of o to 100
130 set height of o to 100
131 set stroke thickness of o to 10
132 end tell
133 end tell</pre>
134
135 And here's how you do it with JSTalk, using a doctored version of Sketch (6 lines of code, + the JSTalk framework):
136
137 <pre class="codeSample">var sketch = [JSTalk application:"Sketch"];
138 var doc = [sketch orderedDocuments][0]
139 var rectangle = [doc makeNewBox];
140
141 [rectangle setWidth:100];
142 [rectangle setHeight:100];
143 [rectangle setXPosition:100];
144 [rectangle setYPosition:100];</pre>
145
146
147 If you aren't a fan of the optional bracket syntax, you can also write the script this way:
148
149 <pre class="codeSample">var sketch = JSTalk.application_("Sketch");
150 var doc = sketch.orderedDocuments()[0]
151 var rectangle = doc.makeNewBox();
152
153 rectangle.setWidth_(100);
154 rectangle.setHeight_(100);
155 rectangle.setXPosition_(100);
156 rectangle.setYPosition_(100);</pre>
157 <br/>
158
159
160 <strong>But no apps out there currently support JSTalk!</strong><br/>
161
162 Applications can also be scripted using Cocoa's Script Bridge class, SBApplication. Here's an example:
163
164 <pre class="codeSample">[[SBApplication application:"iChat"] setStatusMessage:"Happy (funball)"];</pre>
165
166 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.
167 <br/><br/>
168
169
170 <strong>JSTalk Plugins</strong><br/>
171 Aka, loadable bundles which add functionality to JSTalk, via helper classes, wrappers, and categories.<br/><br/>
172
173 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];<br/><br/>
174
175 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.<br/><br/>
176
177
178
179 <strong>But it doesn't do X:</strong><br/>
180 Let us know by sending an email to gus@flyingmeat.com
181 <br/><br/>
182
183 <strong>Mailing list and bug reporting:</strong>
184
185 - Developer mailing list: <a href="http://groups.google.com/group/jstalk-dev">http://groups.google.com/group/jstalk-dev</a>
186 - Bug reporting: <a href="http://jstalk.lighthouseapp.com/projects/26692-jstalk/">http://jstalk.lighthouseapp.com/projects/26692-jstalk/</a><br/><br>
187
188 <strong>Credits:</strong><br/>
189 As said earlier, JSTalk is a blend of existing technologies, and has very little original code in it. Here's what it uses:<br/>
190
191 - JSTalk Icon, from Brad Ellis.<br/>
192 - JavaScriptCore, from Apple and the WebKit team.<br/>
193 - <a href="http://inexdo.com/JSCocoa">JSCocoa</a>, from Patrick Geiller.<br/>
194 - <a href="http://ditchnet.org/tdparsekit/">TDParseKit</a>, from Todd Ditchendorf.<br/>
195 - <a href="http://www.noodlesoft.com/blog/2008/10/05/displaying-line-numbers-with-nstextview/">NoodleLineNumberView</a>, from Paul Kim / Noodlesoft.<br/>
196 - <a href="http://www.lorax.com/FreeStuff/TextExtras.html">TextExtras</a>, from Mike Ferris.<br/>
197
198
199 </div>
200
201
202
203 </div> <!-- main -->
204 </div> <!-- mainBack -->
205
206
207 </body>
208 </html>
Something went wrong with that request. Please try again.