This script automatically manages WiFi and Bluetooth based on your MacBook's lid state, but only when running on battery power. When plugged into power, the script won't make any changes.
- Automatically disables WiFi and Bluetooth when closing the lid (on battery power)
- Automatically enables WiFi and Bluetooth when opening the lid (on battery power)
- Does nothing when the MacBook is plugged into power
- Minimal battery impact (checks status every 2 seconds)
- MacOS
- Homebrew (for installing blueutil)
- blueutil (will be automatically installed if missing)
- Make the script executable:
chmod +x monitor_lid.sh- Run the script:
./monitor_lid.shTo run the script in the background, you can use:
nohup ./monitor_lid.sh &To stop the script, find its process ID and kill it:
ps aux | grep monitor_lid.sh
kill <PID>To make the script start automatically when your Mac boots:
- Copy the LaunchAgent plist to your user's LaunchAgents directory:
cp com.user.lidmonitor.plist ~/Library/LaunchAgents/- Load the LaunchAgent:
launchctl load ~/Library/LaunchAgents/com.user.lidmonitor.plistThe script will now automatically start when you log in. You can check the logs at:
lidmonitor.logfor standard outputlidmonitor.error.logfor any error messages
To stop the auto-start:
launchctl unload ~/Library/LaunchAgents/com.user.lidmonitor.plist