Last active
June 30, 2020 06:16
-
-
Save notanimposter/4a19a0f910192881fe324651b6d83c15 to your computer and use it in GitHub Desktop.
Stop bluetooth from turning on everytime the computer wakes up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
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 | |
fi | |
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 | |
else | |
echo "Usage: btstate <save|load>" | |
#printf "$(date): run without command\n" >> /usr/local/share/btstate/log | |
ficomputer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Starts btstate again on wake | |
After=suspend.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/sbin/service btstate start | |
[Install] | |
WantedBy=suspend.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Save/load bluetooth state | |
After=multi-user.target bluetooth.service | |
Conflicts=suspend.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/btstate load | |
ExecStop=/usr/local/bin/btstate save | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment