Skip to content

Instantly share code, notes, and snippets.

@mijorus
Last active March 25, 2024 13:33
Show Gist options
  • Save mijorus/b9fabea963fabd435139654c6ebe6aae to your computer and use it in GitHub Desktop.
Save mijorus/b9fabea963fabd435139654c6ebe6aae to your computer and use it in GitHub Desktop.
Commands for sleepwatcher for turning on and off wifi and bluetooth automatically on macOS

Install sleepwatcher from brew

Create ~/.sleep file

#!/bin/zsh

echo $(blueutil -p) > ~/.bluestatus
bluestatus=$(head -n 1 ~/.bluestatus)

if [[ "$bluestatus" != "0" ]]; then
    blueutil -p 0
fi

if [[ $(networksetup -getairportpower en0) =~ "On" ]]; then
	echo 1 > ~/.wifistatus
	networksetup -setairportpower en0 off
else
	echo 0 > ~/.wifistatus
fi

Create a ~/.wakeup file

#!/bin/zsh

wifistatus=$(head -n 1 ~/.wifistatus)

if [[ "$wifistatus" != "0" ]]; then
    networksetup -setairportpower en0 on
fi

Run chmod +x .wakeup and chmod +x .sleep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment