Started by fixing  so it would work on Mac OS X, then improved the script in general.