Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Mac Mini Server that's disconnecting every few days or so from the wifi network. There may be other parameters causing the initial disconnection (such as the wireless router being rebooted) but the Mac doesn't automatically reconnect.

It's a major problem since it's a server machine that's suddenly becomes unavailable until someone goes to the machine physically and uses the wifi menu to reconnect manually to the network. I should mention that although the wifi network is WPA2, manually reconnecting doesn't involve re-entering the password so there's no obvious reason why it doesn't reconnect automatically.

How can I get the Mac to periodically try and reconnect to a specified wifi network?

share|improve this question
Is the network in question defined as Preferred? Have you checked in System Preferences > Network that "Remember any network this computer has joined" is checked and "Disconnect from wireless networks when logging out" is unchecked? You could also try to delete and recreate the network connection. – harrymc Oct 10 '11 at 17:39
where exactly is the "Disconnect from wireless networks when logging out" option? It's running Lion. – GJ. Oct 12 '11 at 14:34
Apparently in Advanced settings. – harrymc Oct 12 '11 at 20:54
not to make you paranoid or anything, but the only way to crack WPA2 encryption is to sniff the authentication packets (when a computer connects) and the most common way to do that is to de-authenticate one of the machines and sniff the network when it re-connects. – Nate Koppenhaver Oct 13 '11 at 23:32
up vote 6 down vote accepted

Here is an Applescript and shell script to check if Airport is connected and if not to connect it.

if (do shell script "networksetup -getinfo Wi-Fi | grep -c 'IP address:'") = 1 then
    do shell script "networksetup -setairportnetwork en1 <networkName> <passwordToNetwork>"
end if

if [ $(networksetup -getinfo Wi-Fi | grep -c 'IP address:') = '1' ]
then $(networksetup -setairportnetwork en1 <networkName> <passwordToNetwork>)

Replace with the network's name and with its password. The "en1" should be correct if you have not changed your Network devices.

Now all you need to do is loop this or call it to check the connection.

Nevertheless airport should automatically reconnect if the connection is lost. Maybe try resetting all network preferences and see if that works.

How to completely reset your Network Preferences : Turn Airport off. Close System Preferences. Navigate to : /Library/Preferences/SystemConfiguration/ Make a copy, then delete the following files :*
share|improve this answer
thanks. why use an applescript though? it seems to lend itself more to a shell script perhaps one that runs every minute or so using launchd. – GJ. Oct 18 '11 at 11:15
also, how do you "reset all network preferences" ? – GJ. Oct 18 '11 at 11:15
This could be done with a shell script. Although I'm better at Applescript so I wrote it in Applescript. I'll see if I can write it in a shell script. I've also updated the post on reseting network preferences. – Kassym Dorsel Oct 18 '11 at 13:42
Improved the script and added a shell script. – Kassym Dorsel Oct 18 '11 at 14:56

I would like to just comment Kassym Dorsel answer, but don't have enough points to do so...

I had the same problem with my Mac server:

Wi-Fi connects to VPN and ethernet to LAN, so if Wi-Fi connection is lost, OS X doesn't automatically reconnect.

Considering Kassym Dorsel's answer:

  • I wasn't comfortable having my Wi-Fi password stored in the clear (admittedly it's an extremely low risk, but still).

  • I wanted it to enable wifi if it had been disabled.

  • I wanted it to handle the condition where a static IP was assigned, wifi was enabled, but it was either still not connected or connected to the wrong WIFI network (SSID).

So I modified his script to address these concerns (replace with your preferred network SSID):


    #turn on wifi if it's turned 'Off'
    if [ $(networksetup -getairportpower en1 | grep -c 'Off') = '1' ]
    then $(networksetup -setairportpower en1 on)

    #cycle wifi power if missing 'IP address'
    if [ $(networksetup -getinfo Wi-Fi | grep -c 'IP address:') = '1' ]
    then $(networksetup -setairportpower en1 off; network setup -setairportpower en1 on)

    #initiate connection if not connected to the correct network
    if [ $(networksetup -getairportnetwork en1 | grep -c '<networkName>') = 0]
    then $(networksetup -setairportnetwork en1 '<networkName>')
share|improve this answer

You might try to play with the airport utility (in newer OS X versions it's hidden away in /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport or a similar path).

Specifically, the JoinMode and JoinModeFallback preferences could be useful. On my machine, JoinModeFallback is set to DoNothing by default. Changing it to KeepLooking seems a promising start.

Run airport without arguments to see its help.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.