I have spent about 6 years with 3 Macs with this kind of problem unresolved. I did not have it "in the very beginning", with some ancient versions of Mac OS X etc. Finally decided to look closer and it looks like it could be some "bug" that is related to the extra network settings that programs like VMWare Fusion, VirtualBox etc. leave on the Mac.
Essentially, OS X thinks the Mac is connected to these networks and does not need the Wi-Fi. Luckily, the automation service cron
from the very old days seems to be still working in current Macs (I've read some complaints it doesn't), and I got it to execute a script to connect to Wi-Fi if disconnected. It is a two step process. First, run sudo crontab -e
in Terminal, and paste in that editor:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=user
HOME=/
*/1 * * * * /usr/local/bin/macWiFireconnect.sh
The most important line is the last, which executes macWiFireconnect.sh
every one minute, you can change the 1
if you want. Then, the executable script macWiFireconnect.sh
looks like this:
#!/bin/bash
SERVER=8.8.8.8
ping -c2 ${SERVER} > /dev/null
if [ $? != 0 ]
then
networksetup -setairportnetwork en1 WifiName WifiPassword
fi
Also enable the script to be executable.
sudo chmod 700 /usr/local/bin/macWiFireconnect.sh
So, the script runs the networksetup command if it cannot connect to Google.