Are you tired of your MacBook maintaining Bluetooth and WiFi connections when it's supposed to be sleeping? This can lead to unnecessary battery drain and potential security risks. In this guide, we'll walk you through a simple yet effective solution using SleepWatcher to automatically disable both Bluetooth and WiFi when your MacBook goes to sleep.
Why Disable Bluetooth and WiFi on Sleep?
When your MacBook goes to sleep, it often keeps Bluetooth and WiFi active. While this is convenient for quick wake-ups or maintaining network connections, it can:
- Drain your battery unnecessarily.
- Keep your Mac connected to devices or networks when it's not in use.
- Pose potential security risks by leaving your wireless interfaces active.
By disabling both Bluetooth and WiFi during sleep, you can conserve battery life and improve security.
Step 1: Install SleepWatcher and Blueutil
To get started, you'll need two tools: SleepWatcher (to run scripts when your Mac sleeps or wakes) and Blueutil (to control Bluetooth via the command line).
- Open Terminal.
- Install both tools using Homebrew:
brew install sleepwatcher blueutil
This will install SleepWatcher and Blueutil into the /opt/homebrew
directory.
Step 2: Create Sleep and Wake Scripts
SleepWatcher works by running custom scripts when your Mac sleeps or wakes. You'll create two scripts: one for sleep (to disable Bluetooth and WiFi) and one for wake (to re-enable them).
- Create the sleep script using
Terminal
in~home
directory:
echo "/opt/homebrew/bin/blueutil -p 0" > ~/.sleep
echo "networksetup -setairportpower Wi-Fi off" >> ~/.sleep
- Create the wake script using
Terminal
in~home
directory:
echo "/opt/homebrew/bin/blueutil -p 1" > ~/.wakeup
echo "networksetup -setairportpower Wi-Fi on" >> ~/.wakeup
- Make these scripts executable:
chmod +x ~/.sleep ~/.wakeup
Step 3: Configure SleepWatcher
Start the SleepWatcher service:
brew services start sleepwatcher
Step 4: Make SleepWatcher Start at Login
To ensure SleepWatcher runs automatically whenever you log in, follow these steps:
Option 1: Use Login Items & Extensions (GUI Method)
- Open System Settings on your Mac.
- Go to General > Login Items & Extensions.
- Under Login Items, click the + button.
- Navigate to
/opt/homebrew/Cellar/sleepwatcher/[version]/sbin/
(replace[version]
with the installed version of SleepWatcher, e.g.,2.2.1
). - Select
sleepwatcher
and click Add.
This will add SleepWatcher as a login item so it starts automatically whenever you log in.
Testing Your Setup
To ensure everything is working correctly:
- Close your MacBook lid
- Wait a few seconds
- Open the lid
Both Bluetooth and WiFi should turn off when the lid is closed and turn back on when opened.
Troubleshooting
If you encounter any issues:
- Make sure SleepWatcher is running:
brew services list
- Check your script permissions:
ls -l ~/.sleep ~/.wakeup
- Review system logs for any error messages
Conclusion
By following this guide, you've successfully automated the process of disabling Bluetooth and WiFi whenever your MacBook goes to sleep—and re-enabling them upon waking up! With SleepWatcher configured to start at login, you can enjoy improved battery life, enhanced security, and peace of mind knowing that your wireless interfaces are inactive when not in use.
Remember, you can always modify the sleep and wake scripts to include additional actions or fine-tune the behavior to suit your specific needs.
Happy automating! 😊
Top comments (0)