Update mac.sh

Partially rewritten code for better compatibility