More intermittent OS X build script cleanup. Also ported over commit babe3b19e0451af7ba1571dd4c38a1d19d957de3 in an attempt to fix some user-reported bugs.