Skip to main content

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.

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 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

So, the script runs the networksetup command if it cannot connect to Google.

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.

added 39 characters in body
Source Link
Nimesh Neema
  • 52.9k
  • 25
  • 151
  • 211

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 OSXMac 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, OSXOS X thinks the Mac is connected to these networks and does not need the WiFiWi-Fi. Luckily, the automation service "cron"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 WiFiWi-Fi if disconnected. It is a two step process. First, run "crontab -e"crontab -e in a terminalTerminal, and paste in that editor:

SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=user HOME=/ */1 * * * * /usr/local/bin/macWiFireconnect.sh

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.shmacWiFireconnect.sh every one minute, you can change the 11 if you want. Then, the executable script macWiFireconnect.shmacWiFireconnect.sh looks like this:

#!/bin/bash SERVER=8.8.8.8 ping -c2 ${SERVER} > /dev/null if [ $? != 0 ] then networksetup -setairportnetwork en1 WifiName WifiPassword

#!/bin/bash
SERVER=8.8.8.8
ping -c2 ${SERVER} > /dev/null
if [ $? != 0 ]
then
    networksetup -setairportnetwork en1 WifiName WifiPassword

So, the script runs the networksetup command if it cannot connect to Google. Voila!

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 OSX 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, OSX thinks the Mac is connected to these networks and does not need the WiFi. 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 WiFi if disconnected. It is a two step process. First, run "crontab -e" in a 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, 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

So, the script runs the networksetup command if it cannot connect to Google. Voila!

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 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

So, the script runs the networksetup command if it cannot connect to Google.

Source Link

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 OSX 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, OSX thinks the Mac is connected to these networks and does not need the WiFi. 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 WiFi if disconnected. It is a two step process. First, run "crontab -e" in a 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, 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

So, the script runs the networksetup command if it cannot connect to Google. Voila!