Skip to content

Toggle Wi Fi during sleep wake up

profzei edited this page Jun 9, 2024 · 3 revisions

Depending on the version of AirportItlwm.kext or the macOS release, Wi-Fi may not automatically reconnect to known networks during system wake-up. Toggle off / on Wi-Fi device button makes the trick: but such a solution is very annoying!

For this reason it is possible to automate this procedure using SleepWatcher through Homebrew.

For installing SleepWatcher and its services, please, refer to step #13 and following here.

Here are the additional steps:

  1. Command line to identify network service order:
/usr/sbin/networksetup -listnetworkserviceorder
  1. Create a Sleep and Wakeup file in your home directory:
touch ~/.sleep && chmod 755 ~/.sleep
touch ~/.wakeup  && chmod 755 ~/.wakeup
  1. Put the following script into ~/.sleep to disable the wifi adapter:
#!/bin/bash
/usr/sbin/networksetup setairportpower en1 off
touch /tmp/sleep.log
cat > /tmp/sleep.log
echo "Sleeping: `date`" >> /tmp/sleep.log
echo `/usr/sbin/networksetup getairportpower en1` >> /tmp/sleep.log
  1. Put the following script into ~/.wakeup to re-enable the wifi adapter:
#!/bin/bash
sleep 10
/usr/sbin/networksetup setairportpower en1 on
echo "Waking Up: `date`" >> /tmp/sleep.log
echo `/usr/sbin/networksetup getairportpower en1` >> /tmp/sleep.log
  1. You can see the most recent sleep/wake cycle in the /tmp/sleep.log file:
cat /tmp/sleep.log

Note Your Wi-Fi device should be en1

References

Clone this wiki locally