Skip to content

Instantly share code, notes, and snippets.

@overengineer
Created February 22, 2023 20:51
Show Gist options
  • Save overengineer/a578595dbb52a4af59dd44d2a433ffb1 to your computer and use it in GitHub Desktop.
Save overengineer/a578595dbb52a4af59dd44d2a433ffb1 to your computer and use it in GitHub Desktop.
Connect to bluetooth device
#!/bin/bash
NAME=$1
DEVICE=$(bluetoothctl devices | grep $NAME | awk '{print $2}')
stdbuf -oL -eL bluetoothctl connect $DEVICE 2>&1 \
| tr -dc '[[:print:]]' \
| xargs -I{} ~/scripts/notify-send.sh -t 1000 -f $NAME "{}"
success=$?
sleep 1
if [[ $success == 0 ]]; then
~/scripts/notify-send.sh -t 2000 -f $NAME 'Successfully connected'
else
~/scripts/notify-send.sh -t 2000 -f $NAME 'Failed to connect'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment