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


Working with multiple monitors is a must when doing any serious coding work. Code on one side, output on the other. No more swapping applications from the foreground to background.

Mac OS X make working with multiple monitors a snap: plugin in the secondary monitor, open System Preferences, click on Displays, click on the Arrangement tab and arrange the displays by dragging and dropping. That’s it. In the figure below the larger box is the secondary monitor (larger view area) and the smaller is my laptop.

There is one default setting that I want to mention here that hopefully will save you some time. When you set up an additional monitor the menu bar stays on the original display. Depending on your arrangement, this may be no worry. In my case I wanted the secondary monitor to be the primary display. When working on an application in what is now my primary display, it’s anything but intuitive to move the mouse back over to the laptop display to click a menu item.

I spent some time searching for a tip, trick or hack to fix this little problem, to no avail. I went back into the system settings any number of times looking for a preference setting. I even did a search for a Mac Defaults option to specify where the menu should land. Again, no luck.

Here’s the punch line, the fix was so obvious, it wasn’t obvious. If you look closely at the figure above, notice the second line in the description area…”To relocate the menu bar, drag it to a different display.” Heh, was that there the whole time…??

So here’s the tip: to move the menu bar simply drag-n-drop as you prefer.

Okay, so here’s where I have a question for you. I recently upgraded to Leopard (10.5), and I’m curious if this feature existed on Tiger (10.4)? Essentially I’m looking for an excuse as to why I didn’t see the obvious solution to my question, right in front of me. Maybe you can help me out here :)

MacFUSE is an open source project that simplifies the process of adding a file system to Mac OS X. If you’ve ever had an inclination to create a file system, or thought that a file system like “interface” would be an intuitive approach to solving a problem, yet, upon delving into what it takes to create a kernel extension, you opted to rethink your idea (or at least the approach) here’s where MacFUSE comes in, effectively offering an API to implement a file system.

FUSE (file system in user space) was born and bred as a Linux tool. MacFUSE is a port of FUSE to the Mac by Amit Singh. From the highest level, there are two key aspects to FUSE. First and foremost (without it you have nothing) the dynamically loadable kernel extension. This is where all the hard work (aka magic) takes place. The second aspect is the API, not unlike any other API you’ve worked with, the FUSE library offers an interface to communicate with the kernel extension. Using calls such as read, open and write, working with your own file system on FUSE becomes a rather trivial undertaking.

Following are a few examples of application using MacFUSE:

  • SpotlightFS: an application that dynamically generates smart folders from Spotlight queries
  • SSH FileSystem: file system client based on the SSH

To learn more about MacFUSE, you can watch this video of Amit reviewing his MacWorld 2007 presentation.

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)


In the previous post I showed how to configure and access the various Java versions installed on Leopard. In this post I want to dig a little deeper into what is going on behind the scenes as it relates to working with Java on Mac OS X. None of what I describe here will speed up your development process, however, it may save you some time if/when the day comes that something is amiss when working with Java.

Let’s begin by looking at the setting for JAVA_HOME on my system:

JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home

All works well, despite the fact that this technical article on Apple specifies that JAVA_HOME should point to:

/Library/Java/Home

So what’s up with that? Having a closer look at the file system will reveal what’s going on. The figure below shows a directory listing of the path /Library/Java/Home:

It’s all about symbolic links, so effectively the path Apple recommends, is a link to the path that I have set as my JAVA_HOME. If you look at the listing below you’ll notice that /System/Library/Framework/JavaVM.framework/Home is a link to /System/Library/Framework/JavaVM.framework/Versions/CurrentJDK/Home.

I think you can guess where I’m going with this next. If we look one level deeper, we’ll see that the reference to /CurrentJDK/Home includes a /bin directory, which is where all the Java executables (see below):

The listing below shows the contents of the /bin again, a list of links:

Okay, we’ve got to be nearing the end here…if we list the files that are located at ../../Commands we will finally see the executables, no more links:

What do all the links accomplish versus a simply directory and path structure? In a word, flexibility. Using links, one can change the reference to the /CurrentJDK directory and in one fell swoop, change which executables files (that is, which version of Java is used). Thus, when a new version of Java is downloaded and installed via the Mac OS X Software Update, or you upgrade to a new version of Mac OS X, getting the latest version of Java is nothing more than changing the appropriate symbolic links.

The good news is that unless you manually upgrade Java, all the work happens for you with no effort on your part. However, my intention in jumping through all these hoops is to show you how the linking process works, so if/when the day comes that you need to figure out why the “wrong” Java version is compiling or packaging your code, you have a path (no pun intended) to make some sense of where the “active” Java executables live.

Mac OS X Leopard includes multiple versions of Java in the base install. This can be quite helpful if you need to compile and run Java code across more than one version of the JDK.

You can specify which installed version of Java you prefer to use as the default by tweaking the settings within the Java Preferences application, which is located in the Utilities folder under Java. See the figure below and notice the path reference on the bottom of the figure. The full path is:/Applications/Utilities/Java/

From within the Java Preferences application, in addition to choosing the preferred Java version, there are a number of additional configuration options in the Security and Advanced tabs, with the later tab including a number of options that make it worth a visit.

One last recommendation, if you compile from the command line you can select which version of the Java compiler you are after without having to change the preferred system setting. Open ~/.bash_profile (in your home directory) and create aliases similar to the following:

alias javac-15=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java
alias javac-14=/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Commands/java

Check the Java version using the above aliases as follows:

In the second part of this post I’ll show you some of the goings on behind the scenes of the Java configuration on Mac OS X.

My day job is to lead the developer relations and community building efforts for Mojax, an Ajax framework for writing mobile applications. This type of work is a good fit given I’ve been in software development for nearly 20 years, working in roles from software engineering to training, chief architect to principal consultant, along with the fact that I enjoy an outward facing role that offers the chance to get out and talk technology with others.

The primary goal of an evangelist is to create a thriving community around a technology and/or product. One key aspect of this effort is to educate by providing insightful content and tutorials. To that end, I recently wrote an article for Dr. Dobbs that demonstrates how to build a Mojax application that searches for and displays real-estate property information.

The example that I created is built around the web services offered by Zillow.com, which provides a set of interfaces for accessing real-estate property information.

The figure below is a screen shot of the application running on a mobile device emulator. The information shown is from the primary residence of Bill Gates (and just who has the unenviable job of cleaning those 19+ bathrooms?)

Another tool of a developer evangelist is the screencast. If you’d like to see some of my work, and learn more about Mojax, you can kill two birds with one stone by following the links below:

And I’d be remis if I didn’t tell you that I don’t really advocate killing birds with stones :)

When working in TextMate, if you have a one or more lines of Ruby code that you would like to have the interpreter run, without the need for passing the entire file to the interpreter, this tip may be just what the doctor ordered.

For example, when debugging, often times it would be really handy to run a simple script at a specified location in your code to look at a value, call a method on an Object… The key point here is that you can have as little as one line of Ruby processed by the interpreter and the return value will be inserted inline.

This easiest way to get the gist of this is to watch the screencast below:

If you want to insert the results of one or more lines of script, directly into your code, using # => markers is the way to go.




The music in the video is J.J. Cale and the song: Call Me the Breeze.

A longer clip of J.J. Cale jamming:

When working inside a terminal window, there’s a quick shortcut you can use to open a file (read, launch an application on a specific file or set of files). The beauty of this trick is that the command will work as if you clicked on an application icon(s) in Finder. For example, if you request to open a file with an extension of xml, the application associated with that extension will be started and the specified file will be passed to the application.

The command I am referring to is open; read on to see a few examples:

From a terminal window, to all the files with a “.rb” extension (in the current directory):

> open *.rb

To launch a browser at a specified URL, try this:

> open http://macDeveloperTips.com

And to open Finder in the current directory:

> open .

You can get more information about using the open command by viewing the manual page:

> man open