Various fixes for Mac OS X

Thanks for the great scripts you've provided.  I've attached two fixes that allow the scripts to easily work on Mac OS X