netbeans

In part 1 of this series I demonstrated how to create a short Java application in NetBeans that communicated, using AppleScript, to the Mac apple event system. The application was a no thrills look into how to invoke the TextEdit application. Despite the brevity of the application it provided the foundation for this next tip, which will build on the ideas to create something a little more salient, as in, something that you might actually find yourself using.

The gist of the application is to instruct iTunes to play a random song, move to the next song, pause, etc. I” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”ll show one use of the application by wrapping the code into a bash script that allows you to invoke the program (and all commands) from within a terminal. Watch the video that follows for all the details…

This application is all of about 80 lines, including the bash script. Sometimes a little creative thinking and a few lines of code are all that” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”s needed to write an intriguing (and hopefully useful) application.


The music in the video is Led Zeppelin and the song: Moby Dick. Led Zeppelin at Amazon


A few weeks back I demonstrated how to write Ruby code inside NetBeans to control scriptable applications on a Mac, that is, communicate between Ruby and the Apple Event system. In this post, I will turn things around a bit from the previous post and use NetBeans and Java to execute AppleScript.

There is a subtle difference, in the previous post the focus was on how to write code in Ruby (inside NetBeans) using the rb-appscript bridge. This time around the approach is to work with Java and pass AppleScript code to a set of Cocoa files (classes) that will act as the bridge between our application and the Mac system.

There is one caveat – the Cocoa-Java API is deprecated as of Mac OS X Tiger. The NSAppleScript and NSMutableDictionary classes are still available, however, they are no longer on the development path within Apple. There are scripting bridges that allow you to control scriptable applications using Python, Ruby, and Objective-C. Java Native Interface (JNI) is an additional option to call platform specific code. You can read more about JNI in this technical note: JNI development on Mac OS X.

One more note, if you follow the steps in this video and the classes NSAppleScript and NSMutableDictionary are shown with lines through them (for example, NSAppleScript), this has to do with a preference setting inside NetBeans to show deprecated classes with a strike-through. You can change this as follows: From the Preferences dialog, choose Fonts/Colors; click the Syntax option; from the Language list choose Java; click on Deprecated Element; in the Effects option, choose None.

Join me in Part 2 of this tip where I” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”ll show a more comprehensive (read: interesting) example where it” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”s all about controlling iTunes using Java.


The music in the video is Led Zeppelin and the song: Moby Dick.
Click the image to see more about about Led Zeppelin and the CD (at Amazon)


…NetBeans TV, that is. The short screencast I created on using NetBeans, Ruby and rb-appscript to control scriptable applications on a Mac can now be seen on NetBeans.tv! If you aren’t familiar with NetBeans.tv, it is a popular extension of the NetBeans.org site, focused on connecting the people, projects and technologies surrounding NetBeans.

Rob Demmer from the NetBeans team contacted me about posting the video on NetBeans.tv. I’m all for spreading the word in the developer community and if the video I created can play even a small part in helping to reach a few more developers or otherwise introduce a new technology to this audience, count me in.

As far as NeBeans.tv, there are several sections to the site: Interviews, Community, News, Screencasts and On the Road. The last section is quite interesting as it is a video diary of sorts that chronicles the days and nights of two guys traveling around the world meeting NetBeans developers (which sounds like a great job, if you can get it). It’s an interesting website, definitely worth a look.

If you would like to watch the video, as it appears on the NetBeans.tv site, click the image below:

What do NetBeans, Ruby and AppleScript have in common? There’s a circular definition of sorts to explain…to start, all are tools available to developers working on Mac. Next, NetBeans has full support for creating, debugging and packaging Ruby code. And finally, Ruby (with the right tools in place) can be used within NetBeans to control scriptable applications on a Mac, something which is typically accomplished using AppleScript.

In this post I’ll describe more about how all these tools come together to provide an interesting approach for using Ruby as an alternative to AppleScript, and working with NetBeans as the development environment for writing and building those same applications.

The screencast that follows will walk you through all the steps to download the tools you’ll need, build from source a scripting bridge (rb-appscript) for Ruby to AppleScript, and finally, create several short examples to demonstrate how you can use Ruby, from within NetBeans to control scriptable applications.

For more information, follow these links:

If you are interested to learn more about using Ruby as an alternative to AppleScript, I’ve written as series of posts you can find here: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6

If you write an interesting application in NetBeans, using Ruby and rb-appscript, drop me a note, as I’d like to post several good examples showing the interaction of all these tools.

As an aside, NetBeans is sponsoring a blogging contest for the 6.1 Beta. If you are interested in learning more, visit the NetBeans Blogging Contest. And who knows, you could walk away with one of ten $500 American Express gift certificates!