How to Automatically Disable Wi-Fi When Your Mac Sleeps

Keeping Wi-Fi active during sleep can drain your battery and leave background processes running. While macOS doesn’t have a native “toggle on sleep” switch, you can automate this process using a lightweight utility called SleepWatcher.

Step 1: Install SleepWatcher
First, you need Homebrew installed. Open your Terminal and run:

brew install sleepwatcher
brew services start sleepwatcher

Step 2: Create the Sleep Script
This script tells your Mac to kill the Wi-Fi connection the moment the lid closes or the system enters sleep mode. Run this in Terminal:

nano ~/.sleep

Paste the following code:

#!/bin/bash
networksetup -setnetworkserviceenabled Wi-Fi off

Press CTRL+O to save and CTRL+X to exit.

Step 3: Create the Wake Script
This script ensures your Wi-Fi reconnects automatically when you open your Mac. Run this in Terminal:

nano ~/.wakeup

Paste the following code:

#!/bin/bash
networksetup -setnetworkserviceenabled Wi-Fi on

Press CTRL+O to save and CTRL+X to exit.

Step 4: Set Permissions
You must make these scripts executable for them to work:

chmod +x ~/.sleep ~/.wakeup

Conclusion
Your Mac will now preserve battery life and stay completely offline while sleeping. If you ever want to revert this, simply delete the .sleep and .wakeup files from your home directory

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top