index — dotfiles @ 72ecba9ca9488ab0b95a2973077326ed9770a0cf

my dotfiles

bin/bluetooth-devices (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
#!/bin/sh

#
# This program lists all paired devices which you can select from, the selected one
# will be connected
#   

# Opens dmenu prompt, which lets you decide which device you want to connect to
DEVICE=$(bluetoothctl devices | sed 's/[^ ]* //' | sed 's/[^ ]* //' | dmenu)

# If dmenu was cancelled, exit program
if [ $? -ne 0 ]; then
    exit 1
fi

# Get MAC adress of the device you selected
MAC=$(bluetoothctl devices | grep "$DEVICE" | sed 's/[^ ]* //' | cut -d ' ' -f1)

# Send a notify whether the connection was successful 
if bluetoothctl connect $MAC | grep -q 'successful' 
then
    notify-send -t 5000 -r 2954 -u normal "  Connected successfully to" "     $DEVICE"
else 
    notify-send -t 5000 -r 2954 -u normal "  Couldn't connect to" "     $DEVICE"
fi