Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Stop bluetooth from turning on everytime the computer wakes up
# Put the .service files in /etc/systemd/system/
# and the btstate file in /usr/local/bin/
# Then run these commands.
sudo chmod +x /usr/local/bin/btstate
sudo systemctl enable btstate.service
sudo systemctl enable btstate-startonwake.service
# You might have to change "hci0" in the /usr/local/bin/btstate file to
# whatever your bluetooth device is called. You can find it by running
# hciconfig. hci0 is what it's called on my system.
if [ ! -d "/usr/local/share/btstate" ] || [ ! -f "/usr/local/share/btstate/state" ] || [ ! -f "/usr/local/share/btstate/log" ]; then
mkdir -p /usr/local/share/btstate
touch /usr/local/share/btstate/state
touch /usr/local/share/btstate/log
if [[ $1 == 'save' ]]; then
hciconfig hci0 | awk '/UP|DOWN/ {$1=$1;print tolower($1)}' > /usr/local/share/btstate/state
#printf "$(date): saved\n" >> /usr/local/share/btstate/log
elif [[ $1 == 'load' ]]; then
hciconfig hci0 `cat /usr/local/share/btstate/state`
#printf "$(date): loaded\n" >> /usr/local/share/btstate/log
echo "Usage: btstate <save|load>"
#printf "$(date): run without command\n" >> /usr/local/share/btstate/log
Description=Starts btstate again on wake
ExecStart=/usr/sbin/service btstate start
Description=Save/load bluetooth state bluetooth.service
ExecStart=/usr/local/bin/btstate load
ExecStop=/usr/local/bin/btstate save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment