Robustified script; OS-specific sections for Mac/Linux