Friday, March 27th, 2009

JSTalk: AppleScript without the weird language

Category: Apple, JavaScript

Gus Mueller has announced JSTalk, an alternative to AppleScript that uses JavaScript and the JSCocoa bridge, and an Objective-J-like language alternative to hide the ugly_methods_when_needed.

Here is Gus:

JSTalk’s goal can described like this: JSTalk is to AppleScript, what Cocoa is to Carbon.

I know, I know. It’s a lofty, crazy goal. But someone has do try and it doesn’t look like the solution is coming from Apple anytime soon. So I’m keeping it very simple, and very easy.

JSTalk isn’t anything new. You write your scripts in JavaScript, and application communication is handled via Cocoa’s distributed objects. Like PyObjc and RubyCocoa, JSTalk uses a bridge to talk to Cocoa (JSCocoa + WebKit’s JavaScriptCore), so you get all the power and speed that comes with it. JSTalk comes with a little editor, a command line tool, and an automator action. If an application you want to script isn’t exposed via JSTalk, you can still tell it what to do via the Cocoa Script Bridge (which is new to 10.5). Here’s an example which sets your iChat status using this technique:

javascript

  1. SBApplication.application("iChat").setStatusMessage("Happy (funball)");

Here’s a JSTalk script which works on a build of Apple’s Sketch sample code, with native JSTalk support added:

javascript

  1. var sketch = JSTalk.application("Sketch");
  2. var doc = sketch.orderedDocuments()[0];
  3. var rectangle = doc.makeNewBox();
  4. rectangle.setWidth(100);
  5. rectangle.setHeight(100);

Read more and fork the code on GitHub!

Posted by Dion Almaer at 1:16 am
Comment here

++++-
4.2 rating from 33 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.