Archive for April, 2007

Using Launchy for application launching

Saturday, April 14th, 2007

I work with someone from OCI who has noted that there are a finite number of keystrokes within his fingers, so every one needs to count. This leads us geeky developer-types to take advantage of shortcuts within our IDEs and frequently-used programs. I have found an application that extends this mindset seamlessly into the Windows OS. It has made my use of Windows extremely fast. In fact, while pair programming or demonstrating something, more than one other programmer has seen me use this tool and asked something along the lines of “What was that thing you just used to open [some program] so quickly?”.

So I’ll tell you.

Launchy is probably the most useful free Windows productivity application I’ve ever downloaded. I use it all the time, sometimes hundreds of times a day. From the Launchy website:

Launchy is a free windows utility designed to help you forget about your start menu, the icons on your desktop, and even your file manager.

Launchy indexes the programs in your start menu and can launch your documents, project files, folders, and bookmarks with just a few keystrokes!

For my first example, compare the following methods of opening Firefox, assuming your hands are where they should be… on the keyboard:

Without Launchy
  1. Remove right hand from keyboard.
  2. Move mouse cursor to either:
    • Firefox desktop shortcut
    • Firefox quicklaunch icon
    • Start –> All Programs –> Mozilla –> Firefox
  3. Click mouse button.
With Launchy
  1. Type: Alt+Space, fire, Enter

Bookmarks

Even better, Launchy indexes all my bookmarks so I can just type “Alt+Space, danlog, Enter” to bring up my weblog. Launchy keeps track of your most recently used applications and tries to guess which one you mean when you type “danlog“.

Media

You can also tell Launchy which directories it needs to index, and what types of files to index. So you can put all your MP3’s in your music directory at your fingertips. Want to listen to Beercan by Beck, just type “Atl+Space, beercan, Enter“, and it pops up in your default MP3 player.

Navigation

Also use Launchy to navigate to the most-used locations in your file directory. I have a folder that Launchy keeps indexed where a bunch of shortcuts exists (Windows .lnk files). So if I want to go to my Eclipse workspace, there is a workspace.lnk within that folder, so I can just type “Alt+Space, work, Enter” to bring the folder up.

Scripts

Some of the most useful things I’ve done with Launchy include custom batch programming. There are some Ant tasks for projects I’m working on that I tend to run all the time, so I have written some very simple batch scripts and placed them into Launchy’s index. Now I can just type “Alt+Space, report, Enter” to open up a command window, navigate to my project folder, and run “ant report” from the command line.

Anything!

You can put any folder into Launchy’s index and have it look and attempt to execute any file type. It will open data or media files with the default program if one is specified. I’ve even put my Windows “recent” link within the index so I can bring up all my recent files with a few keystrokes.

If you are concerned about how many keystrokes you have left in your fingers, I urge you to check out Launchy.

Links


Changing path and environment in Java ProcessBuilder

Friday, April 13th, 2007

The new Java ProcessBuilder in 1.5 is very nice. But there are a few unexpected issues that I ran into while attempted to create an executable-wrapping framework with it.

The first and most important issue is this: Changes to the Path environment variable are not reflected until a new process is created and running. Here is an example of how this can bite you in the ass:

ProcessBuilder pb =
    new ProcessBuilder(”myExe.exe”, “arg1″, “arg2″);
Map env = pb.environment();

// watch out here! this could be “PATH” or “path”
// Windows doesn’t care, but Java will
String path = env.get(”Path”);
env.set(”Path”, path + File.pathSeparator
    + “path\to\the\executable”);

pb.start();

  1. You have an executable file that you want to run with ProcessBuilder that is not on your path.
  2. You assume that you can write the previous code in order to temporarily add the exe’s path to the process’s environment before executing it.
  3. You always get an error=2 back from the ProcessBuilder because it cannot find the file.

This is because the changes you made to the new process environment are not reflected until the process is actually running. In other words, Java does not change the path until it attempts to execute the command you have told it to execute. It will never find an executable file that is not on the previous system path even if you change the “Path” environment variable in the ProcessBuilder before you call the “start()” method.

I think the best way to go about accomplishing this is to send the executable’s absolute path into the ProcessBuilder as the command. It may be inconvenient for you, but you can never depend on a certain path within the user environment once the application is installed (unless, of course, this is on a web server that you have complete control over… in that case just add the executable to your path and carry on happily).