Open class listed in Java Stack Trace in Eclipse

I whipped up a little Mac OS X service today (using ThisService 2.0.2 and AppleScript).

Where I'm working right now we run WebObjects applications (which are written in Java of course) in the Terminal. If there's an exception, a stack trace is written to the Terminal. We'll find and remember an interesting stack frame from the trace (which includes the class name and the line number), then switch to Eclipse, load that class into an editor and jump to the line number.

This service automates that process. Just triple-click the stack frame's line in Terminal and activate this service. It will (using AppleScript) activate Eclipse, and then load the class using the Cmd-Shift-T keyboard shortcut, and then go to the line number using the Cmd-L keyboard shortcut. (If you have removed or changed those shortcuts, this service will not work.)

How to install in Mac OS X Snow Leopard:

Download http://files.me.com/roepcke/9zxcla

In System Preferences > Universal Access, turn on "Enable access for assistive devices".

Decompress this downloaded zip file and copy the .service file into ~/Library/Services.

In System Preferences > Keyboard, select Services on the left, and enable the "Open Selected Stack Trace line..." service. You can optionally set a keyboard shortcut by double-clicking on the right of that row. I used command-option-control-f, but it's up to you.

Note: if you set a keyboard shortcut for the service, you MUST LET GO OF THE KEYS AS SOON AS POSSIBLE after activating the service, as it works by simulating key presses in Eclipse. If you still have the keys for the service's shortcut pressed, the service will fail.

Also note, if you have multiple Eclipse instances open, I have NO IDEA which one will be activated. And if Eclipse isn't already open, it will launch an Eclipse (not necessarily the one you want if you have more than one) but will fail after that. Launch Eclipse fully before using the service!

Absolutely no warranty implied or given. I release the bundled AppleScript into the public domain.

PS: I'm not an AppleScript programmer, so I'm sure the code looks horrible, but it "works for me". :)

Written on November 21, 2009