This man is refusing to connect with his WIFI

Fixing Slow Macbook WIFI Reconnect after sleep.

Apple is, as of this writing, the richest company in the world. It’s been rather well-to-do for decades now. Sickeningly Apple still has problems with something as basic as their laptop models waking from sleep.

I am my family’s tech support guy. I have been choosing, supporting, and servicing their computers for as long as personal computing has been popular. Over that time I have noticed a pattern: many of the Apple laptops my family used have had troubles waking from sleep. Some refuse to wake up at all and must be power-cycled. Others simply take a long time to connect up to the previous WIFI network. This post is for the latter group. If you have to reboot after sleep you probably need to take your computer in to be examined by a repair professional.

Macbook Pros are notoriously slow to reconnect to WIFI after waking. There are many suggested fixes you can Google, but if you do you’ll notice many bitter comment-section entries resembling “that didn’t work for me.” Another theme you’ll notice is that turning wifi on and off right after the laptop wakes up creates an almost instant reconnection to the network, which is far better then the 30–60 second delay a normal wake-up causes.

I decided the only way to deal with this was to write some sort of code that would notice when my Macbook wakes up and automatically turn its WIFI on and off again. I did, and it works.

I don’t have time for a detailed tutorial here, but if you know basic command-line scripting the pieces I describe here will be enough for you. If you, the reader, want a step-by-step tutorial, let me know in the comments and I’ll write one up when I have more time.

The pieces:

Something to run any script when the laptop wakes up

Go to http://www.bernhard-baehr.de/ where you will find the awesome, opensource “SleepWatcher.” Download and uncompress it. The instructions are in the Readme.rtf file that accompanies the folder. You just have to move two files and you’re ready to go. Thank you, Bernhard Baehr!

A command to turn the WIFI on and off

There’s a thorough discussion of this here. It boils down to this:

networksetup -setairportpower airport off

Followed by the same but with “on” replacing “off”.

Here’s the script file I made:

#!/bin/sh
now=$(date +"%T")
echo "Fixing MacOS stupidity at $now"
networksetup -setairportpower airport off
networksetup -setairportpower airport on

In this command the “airport” part is the name of your WIFI “network device.” Of course it varies from system version to system version and may also vary based on other factors. Awesome! But I’ve noticed that mine manages to work even when my network device name is “en0” (last letter is zero) because the networksetup command defaults to whatever device is connected if there’s only one. If you’re having trouble check the info link for details.

Connect the watcher with the do-er

Now you have all the pieces and they just have to be joined together and activated. To do this manually you just need to type the right command into the CLI. (True of nearly everything in life.)

/path/to/sleepwatcher --verbose --wakeup /path/to/your/script

Assuming you got your paths right and you didn’t forget to make your script executable (chmod 755 scriptname), it should now be working. Close your laptop for a few seconds, open it, and watch the little WIFI zebra tornado flash on and off.

For reference here’s the full command I use (all on one line):

/usr/local/sbin/sleepwatcher --verbose --wakeup ~/waykeywaykey/waykeywaykey.sh

Start it all automatically on login

If you don’t want to launch this manually every time you re-log, you’ll need another script file that you paste the sleepwatcher launch command (above) into. Once you do that you can use the preferences pane’s User’s panel to add it as a login item for your user account.

That’s it! Stupid, right? Yep, very stupid.

Apple has had this problem for years. Who knows when/if they’ll fix it.

Like what you read? Give airbag moments a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.