Friday, November 07, 2008

Yes, You Can Dump MS Outlook

When you buy a new Windows system, you will likely have Outlook Express preinstalled (I don't know anyone who uses it these days). Worse, you may feel inclined to dish out $85 for MS Office Standard 2007 (which includes MS Outlook) because the Windows office productivity space is crowded by Microsoft products. If that's all your workplace supports (because they use Exchange servers), you have no choice. But what if you could dump all that for a free email, calendar, and task management solution? It's easy and attainable.

For email, install Mozilla Thunderbird. It does everything MS Outlook does as far as sending and receiving emails, and I think perhaps a little smarter in organizing your mail, searching, and customizing. One caution: resist the temptation to import settings from other mail clients - it gets messy within Thunderbird.
You need the Lightning plugin to add task and calendaring features: download and save the .xpi, then from TB, install it using Tools | Add-ons. After TB restarts, viola! Il y a un calendrier.

Since I routinely work on more than 3 computers, I need them all to have my updated schedule at all times. For this, online calendars provide the needed synchronization link. If you use Google Calendar, you can set up Lightning to synchronize with it from Thunderbird, like this:
Download yet another plugin - the Provider for Google Calendar. After installing it as an add-on for Thunderbird and restarting:
  1. Open your Google Calendar from a web browser
  2. Click on Settings, then on the Calendars tab, click on your calendar.
  3. Scroll to the Private Address area (bottom) and right-click the XML link to copy its URL.
  4. In Thunderbird, select File | New | Calendar : On the network : Google Calendar (and paste the URL here) : provide credentials.
That's all. Since all your calendars now feed off the same online calendar, your computers always have an updated copy whenever you run Thunderbird. This is a totally winning solution that's free and effective. At this point I was ready to backup my messages in Outlook and uninstall it from all my computers. I haven't seen issues in a couple of months since I did this.

Sunday, November 02, 2008

Launch OS Applications From Java

It's not a good idea to reinvent the wheel when programming for various platforms; you'll live happier when you can just use what the operating system already offers - straight from your Java application. This is especially helpful if the OS program you are interested in supports command-line invocations: this tip shows how to run those programs and capture the output those programs would produce back into your Java application. Then you could use regular expression or other means to parse the output.
Here's all you need:
    public static List<String> runCommand (String... cmd) {
List<String> output = new ArrayList<String>();
try {
// Create the process
ProcessBuilder pb = new ProcessBuilder(cmd);
Process proc = pb.start();

// Obtain the input stream
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

// Read what is returned by the command
String line;
while ((line = br.readLine()) != null) {
output.add(line);
}

// Close the stream
br.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}

// Return the output
return output;
}
As a utility method, just pass it an array of strings used to build the command, first the fully-qualified name of the program to invoke, followed by program arguments. For example, if I needed to run a Perl script called lockdown.pl and have the Perl interpreter at C:\Perl\perl.exe, then the string array would be something like {"c:\\perl\\perl.exe", "c:\\security\\lockdown.pl"} - notice the use of fully-qualified names everywhere - this process is cross-platform and doesn't look up environment variables to help resolve relative filenames.
The methods returns the output - what you would have seen on the console - as a list line by line. Easy stuff.