Keep WiFi connection when locking screen

Challenge

My WiFi connection keeps getting lost when locking my screen and I don’t want that.

Solution

  • Find your Wifi network card name, it should be en0 or en1.
  • Open Terminal.app
  • ifconfig
  • Look for the en? that contains the inet item (ip address). That’s the one you need
  • Then do in Terminal.app
1
2
cd /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/
sudo ./airport en0 prefs DisconnectOnLogout=NO
  • That’s it
  • You should be able to lock the screen and still keep the internet connection.

Notes

  • You only need to do the above exercise once. It will be remembered.
  • the en0 in the example needs to be replaced by the one you found of course.
  • The shortcut key for locking the screen is CONTROL + SHIFT + EJECT or CONTROL + SHIFT + POWER
  • When using the lock from the Alfred app this won’t work. I haven’t fount the solution for it yet

Show prefs

to see how the en? interface is configured you can also do the following

1
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs
1
2
3
4
5
6
7
8
9
10
AirPort preferences for en0:
DisconnectOnLogout=NO
Unable to retrieve JoinMode
JoinModeFallback=DoNothing
RememberRecentNetworks=YES
RequireAdminIBSS=NO
RequireAdminNetworkChange=NO
RequireAdminPowerToggle=NO
WoWEnabled=NO

You can google what they all mean :-)

Example commands

Example 1

Having trouble automatically reconnecting your unattended Mac to a wireless network because of unreliable signal quality? If you would like to have it keep reattempting reconnection until it manages to connect…

1
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs joinmode=automatic joinmodefallback=keeplooking

JoinMode (String)

  • Automatic
  • Preferred
  • Ranked
  • Recent
  • Strongest

JoinModeFallback (String)

  • Prompt
  • JoinOpen
  • KeepLooking
  • DoNothing

Example 2

Scan for networks from the command line

1
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s