commits
tags
#!/bin/sh
# bluetooth module -- dispatched by subcommand:
# bluetooth.sh -> bar text, "On"/"Off" (adapter power state)
# bluetooth.sh pair -> "Pair last found device" popup action. No
# interactive device list -- targets whichever
# device bluetoothctl saw most recently.
# bluetooth.sh menu -> popup definition, read once at startup (see
# README, "Module-declared menus")
mode="${1:-status}"
case "$mode" in
menu)
self="$0"
echo 'popup : hover : buttons'
echo 'popup_item : "Turn on" : "bluetoothctl power on"'
echo 'popup_item : "Turn off" : "bluetoothctl power off"'
echo 'popup_item : "Search for devices" : "bluetoothctl --timeout 10 scan on"'
echo "popup_item : \"Pair last found device\" : \"$self pair\""
;;
status)
bluetoothctl show 2>/dev/null | grep -q 'Powered: yes' && echo 'On' || echo 'Off'
;;
pair)
m=$(bluetoothctl devices | tail -n1 | awk '{print $2}')
[ -n "$m" ] && bluetoothctl pair "$m" && bluetoothctl trust "$m" && bluetoothctl connect "$m"
;;
esac