Last active
May 9, 2020 22:18
-
-
Save ofen/ce24ef20f106b0fc8b6391f44b4fb3f6 to your computer and use it in GitHub Desktop.
Simple Bluetooth auto-connect script for systemd
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=/etc/rc.local Compatibility | |
Documentation=man:systemd-rc-local-generator(8) | |
ConditionFileIsExecutable=/etc/rc.local | |
After=network.target | |
[Service] | |
Type=simple | |
ExecStart=/etc/rc.local start | |
ExecStop=/etc/rc.local stop | |
TimeoutSec=0 | |
RemainAfterExit=yes | |
GuessMainPID=no | |
Restart=on-failure | |
RestartSec=5s |
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/sh | |
ARG="$1" | |
DEVICE_MAC="A0:B1:C2:D3:E4:F5" | |
start() { | |
bluetoothctl connect "$DEVICE_MAC" | |
while bluetoothctl info "$DEVICE_MAC" | grep -c 'Connected: yes' > /dev/null; do | |
echo "Device $DEVICE_MAC connected" | |
sleep 5 | |
done | |
echo "Device $DEVICE_MAC disconnected" | |
exit 1 | |
} | |
stop() { | |
bluetoothctl disconnect "$DEVICE_MAC" | |
} | |
case "$ARG" in | |
start ) start;; | |
stop ) stop;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment