Based on patch by dalerank, tested on Windows, might need to be amended for OSX. This was SVN commit r17870.
4741e896c4