How to Automatically Disable Bluetooth and WiFi on MacBook Sleep

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 u…


This content originally appeared on DEV Community and was authored by Shawon Saha

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).

  1. Open Terminal.
  2. 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).

  1. Create the sleep script using Terminal in ~home directory:
echo "/opt/homebrew/bin/blueutil -p 0" > ~/.sleep
echo "networksetup -setairportpower Wi-Fi off" >> ~/.sleep
  1. Create the wake script using Terminal in ~home directory:
echo "/opt/homebrew/bin/blueutil -p 1" > ~/.wakeup
echo "networksetup -setairportpower Wi-Fi on" >> ~/.wakeup
  1. 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)

  1. Open System Settings on your Mac.
  2. Go to General > Login Items & Extensions.
  3. Under Login Items, click the + button.
  4. Navigate to /opt/homebrew/Cellar/sleepwatcher/[version]/sbin/ (replace [version] with the installed version of SleepWatcher, e.g., 2.2.1).
  5. 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:

  1. Close your MacBook lid
  2. Wait a few seconds
  3. 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! 😊


This content originally appeared on DEV Community and was authored by Shawon Saha


Print Share Comment Cite Upload Translate Updates
APA

Shawon Saha | Sciencx (2025-02-22T17:54:09+00:00) How to Automatically Disable Bluetooth and WiFi on MacBook Sleep. Retrieved from https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/

MLA
" » How to Automatically Disable Bluetooth and WiFi on MacBook Sleep." Shawon Saha | Sciencx - Saturday February 22, 2025, https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/
HARVARD
Shawon Saha | Sciencx Saturday February 22, 2025 » How to Automatically Disable Bluetooth and WiFi on MacBook Sleep., viewed ,<https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/>
VANCOUVER
Shawon Saha | Sciencx - » How to Automatically Disable Bluetooth and WiFi on MacBook Sleep. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/
CHICAGO
" » How to Automatically Disable Bluetooth and WiFi on MacBook Sleep." Shawon Saha | Sciencx - Accessed . https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/
IEEE
" » How to Automatically Disable Bluetooth and WiFi on MacBook Sleep." Shawon Saha | Sciencx [Online]. Available: https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/. [Accessed: ]
rf:citation
» How to Automatically Disable Bluetooth and WiFi on MacBook Sleep | Shawon Saha | Sciencx | https://www.scien.cx/2025/02/22/how-to-automatically-disable-bluetooth-and-wifi-on-macbook-sleep/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.