Rhino+Dashboard… it’s like crack

If you are a JavaScript junkie who is in constant need of a fix… here’s a little Dashboard trick I like to use to keep an interactive JavaScript prompt available at all times.

(works for Python and Ruby junkies too)

Dashboard+Rhino crack

  1. Download the WidgetTerm Dashboard Widget. WidgetTerm is basically like Terminal.app in Widget form (although I believe it’s actually based on the open source iTerm application).
  2. Download Rhino 1.6… Mozilla’s Java-based implementation of JavaScript 1.5 + E4X + JS interactive interpreter + JS-2-Java bridge.
  3. After unpacking Rhino, put its js.jar file on your classpath. If you’re not a Java developer, this is easy… just drop js.jar in ~/Library/Java/Extensions.
  4. Now edit this file: ~/.bashrc in your text editor of choice. If it doesn’t exist, just create it. Place the following line in that file:
    
    alias js='java org.mozilla.javascript.tools.shell.Main'
    
    

    Quit and restart Terminal.app (or just source .bashrc). You now have access to a command-line interactive JavaScript interpreter just like the ones provided by Python and Ruby. All you have to do is open a Terminal.app window and type js. BAM… live JavaScript interpreter.

  5. Now then… You have installed WidgetTerm right? Good. Activate Dashboard and drag a new WidgetTerm Widget out from the Widget Bar onto the screen. Type js.

There you have it. Now accessing a live JavaScript interpreter is as easy as activating Dashboard.

Since Python and Ruby both have interactive interpreters by default, you can use this trick for them too… I like to have a Python and a JavaScript WidgetTerm open at all times. :)


About this entry