Shortcut to Groovy on Windows

I frequently find myself wanting to reach for my favorite toy when I need to do something ad-hoc. Whether its iterating local files and echoing their paths to the end of a text document or scanning my Music folder to pull out all of the “.m4a” files. No matter what the job I always have the same reflex to reach for my toy. It always feels just out of reach so I have to stretch a little to get it. Hi, I’m Cliff. You’re here because you played with toys when you were younger. Maybe your toys were cooler than mine. Maybe your family could afford the entire Voltron set whereas we could only buy the blue lion. Maybe your toys are rusty now and maybe my toy is better than yours. My favorite toy these days is Groovy. Now that I’m spending more time on Windows (XP not Longhorn, not Vista, not 7, just reliable ol’ XP), I’ve gotten used to the “open command here” power toy that puts a command prompt pointing to the selected folder in Explorer. Lots of times I use this and then run “groovyConsole”. (Recently I’d been experiencing %Path% issue so its been a little more complicated but we’ll save that for another post.) I’m going to share my latest little shortcut/tip with you.

Run Groovy Here
The same way the Cmd Here will point a command prompt to a folder I hack the registry to get Groovy to launch in whatever folder you right click in Explorer. Assuming you have Groovy’s bin folder in your %Path% use these steps.

  • Hit WinKey+R and type regedit in the run dialog.
  • drill into the path HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell and create a key called “RunGroovy” without the quotes.
  • Double click (or edit) the Default entry and add whatever text you want to show in Explorer’s right mouse menu. I use “Run Groovy Here” but you could use “Format C:”, “Hack The White House”, “Legalize the Herb” or whatever strikes you as appropriate.
  • Create a key within that key (right clicking under the default entry) and name it command.
  • Use the following in the default entry: cmd.exe /c “cd %1 && groovyConsole”

The change takes effect immediately and you may now poke around your file system opening a Groovy console in random locations. Why should you care? Well, for starters, its a quick way to start scripting over a particular directory. All of your objects can be coded relative to the folder you launched from. So if you run it from “C:\Documents and Settings\Clifton\My Documents\My Music” you can write an easy one-liner that iterates your mp3 collection like so:
new File(“.”).eachFileRecurse { if(‘mp3’)) print it + ‘\n’ }

But I write mobile??!! I don’t know Groovy!!!
All the more reason to love Groovy! Assuming you’ve spent a good amount of your time with J2ME and pre-processors you already know Groovy. Install it from the home site, open the Groovy Console and start writing Java code. The syntax starts off roughly 90% the same as Java! You just have to use regular 1.5 Javadocs instead of MIDP2 and/or CLDC Javadocs which a very similar in the available classes. The better news is that you get a refreshing break from the restrictions of J2ME as you get a richer API and way more features. So what can you use it for since It doesn’t run on the phones yet? There at least a dozen every day tasks that would be easier managed in Groovy. A batch image processor that finds files locally and runs them through another program then stages them in your J2ME project is one example. A deployment script that takes your compiled source, logs into a remote server then pushes the MIDlet to a running OTA server is another. You could even write a script that launches an emulator under a virtual machine hosted in Parallels or VMWare and points it to your compiled MIDlet, if you were a Mac user. The possibilities are endless.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s