Status
No public Twitter messages.
Location
Washington, DC
Subscribe to GeoRSS Subscribe to KML


Down with Applescript, up with Javascript!

Published in Apple, Programming, Technology  |  3 Comments


I’ve been fiddling with Applescript on and off for about a year, using it in various applications, and home automation tasks. However, I always feel like I’m bashing my head against it. It doesn’t seem to always make sense, has an odd syntax, and the Dictionaries? Hah! Unreadable is a good, but incomplete, description.

Anyways, for other projects/work on Windows I’ve been implementing a Javascript interface to the application’s functionality & dark, musty interiors. Javascript, once beginning to go the way of Java, Fortran, or Smalltalk (yes, they’re out there, but does anyone learn these anymore?), it has been completely revitalized and now seems to be the cool, modern-way to do webapps/sites (Ajax, Widgets, GreaseMonkey, Firefox Extensions, and more).

Applescript has had a good run, yay. However, it seems antiquated to keep up a proprietary and somewhat odd OS Scripting language. Furthermore, it’s not really a scripting language since it is compiled rather than intepreted.

SpiderMonkey is a Javascript-C engine that allows developers to provide an Javascript API to their applications similar to Applescript integration to Cocoa Apps.

Javascript is a pretty nice syntax. I really wonder how many non-programmers really feel more comfortable in the “English-like” syntax of Applescript. I, as a programmer, find it confusing at times. Though Script Editor is a very nice tool even though it apparently hasn’t been updated in years.

Javascript enabling OS X apps would prevent widgets from having to do things like:


var obj = widget.system("/usr/bin/osascript -e 'tell application "iTunes"' -e 'name of current track' -e 'end tell'");

print(obj.outputString);

and requiring a widget access to the system to make a call to an app. A better solution may be:


var string = application.iTunes.getCurrentTrack();

or


var string = finder.geApplication("iTunes").getCurrentTrack();

Really, I’m missing decent scripting of apps and the OS in Windows, and Linux. Apple really shines in this respect. Windows has scripting via VBScript and JScript, but I’m looking for something a little less… proprietary and even more arcane.

Similar Posts


Responses

  1. Joseph says:

    September 30th, 2005 at 7:32 am (#)

    I have spent 5 years developing a “portable OS” for the Internet which provides significant advantages for websites and portable applications (rich internet apps). Much of the technology base is built with javascript, and moreover, it provides programmers and students alike to develop webpages and scripts – online, which means they are accessible from any modern computer.

    Using this platform and its “focused solution” data is already portable using a Graphical User Interface (GUI). A good example of this, one that brings windows into your browser, is found at http://goGUI.com.

    The next step is to make “portable Applications” a reality. Imagine a license for a porfessiona office suite that doesn’t have to be installed on a single computer, and can be used from any modern computer – quickly, efficiently and interactively.

    If you register at GoGUI, you may create and edit online webpages and scripts (javascript). These scripts, like all files within your portable desktop, and its PI explorer (just like windows explorer only portable) can be moved and managed as easily online, as they are in a static operating system such as MS Windsows.

  2. Barry says:

    October 26th, 2005 at 2:14 pm (#)

    Apple’s scripting underpinning is really the core Apple Events mechanism, where scriptable applications receive events from outside processes (like scripts) and respond. The nice bit is that Apple has defined what they call the Open Scripting Architecture (OSA) which allows other scripting languages to be used in place of AppleScript.

    Take a look at http://www.latenightsw.com/freeware/JavaScriptOSA for a free implementation of JavaScript for OSA. This lets you use JavaScript in place of AppleScript, even in Apple’s Script Editor. Just be sure to set the default language to “JavaScript” in Script Editor’s preferences window.

  3. Peter da Silva says:

    January 19th, 2006 at 9:58 am (#)

    I would think the logical thing for Apple to do would be to provide a mapping between Javascript and the applications Applescript dictionary, rather than having applications adapt to a new API.

    For example:

    var obj = widget.system(”/usr/bin/osascript -e ‘tell application “iTunes”‘ -e ‘name of current track’ -e ‘end tell’”);

    var iTunes=osascript.open(”iTunes”);
    var track=iTunes.get(”name of current track”); // or whatever the short form of that value is in the dictionary.

    JavaScriptOSA seems a little low level, how would I convert an existing Applescript to JavaScriptOSA? For example:

    tell application “iTunes”
    if selection is not {} then
    set sel to selection
    repeat with this_track in sel
    try
    set shufflable of this_track to 1
    end try
    end repeat
    display dialog “Done!” buttons {”Thanks”} default button 1 with icon 1 giving up after 15
    else
    display dialog “Select some tracks first…” buttons {”Cancel”} default button 1 with icon 2 giving up after 15
    end if
    end tell

Leave a Response