#!/bin/bash set -e [ -n "$DEBUG" ] && set -x export UNSAFE=1 # notifysend() { # [ -z "$notifyicon" ] && notifyicon=bluetooth # local msg=$1 # shift 1 # echo "$msg" # notification_id=$(notify-send "bluetooth" "$msg" -i "$(iconez -sn "$notifyicon")" --print-id "$@") # } if [ -n "$BTON" ]; then bluetoothctl power on exit $? fi if [ -n "$BTOFF" ]; then bluetoothctl power off exit $? fi if [ -n "$BTCONNECT" ]; then if [ -n "$REEXEC" ]; then addr=$1 if bluetoothctl devices Connected | grep -q "$addr"; then bluetoothctl disconnect "$addr" else bluetoothctl connect "$addr" sleep 2 # hack to make wireplumber detect bt audio device pkill -USR2 wireplumber fi exit $? fi bluetoothctl power on bluetoothctl devices | while read -r btdev; do name=$(cut -d' ' -f3 <<<"$btdev") addr=$(cut -d' ' -f2 <<<"$btdev") jq -cnr \ --arg label "$name $addr" \ --arg addr "$addr" \ '{l:$label,x:(["env BTCONNECT=1 REEXEC=1 bluemenu", $addr]|join(" "))}' done | jq -cs '{p:"bluemenu", o:.}' | mkmenu exit $? fi jq -cn '{p:"bluetooth",o:[{l:"power on",x:"env BTON=1 bluemenu"},{l:"power off",x:"env BTOFF=1 bluemenu"},{l:"connect...",x:"env BTCONNECT=1 bluemenu"}]}' | mkmenu