mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

bluetooth_connect (644B)


      1 #!/bin/bash
      2 
      3 set -e
      4 set -x
      5 FILE="$HOME/config/private/bluetooth"
      6 DEVICE="$1"
      7 HW=$(grep "^$DEVICE\s" "$FILE" | cut -d' ' -f2)
      8 if [[ -z "$HW" ]]
      9 then
     10   >&2 echo "no registered device $DEVICE in $FILE"
     11   >&2 echo "try adding one from paired devices?"
     12   # echo "paired-devices" | bluetoothctl 2>/dev/null | grep '^Device'
     13   exit 2
     14 fi
     15 
     16 
     17 ID=$(rfkill list | grep -i hci0 | cut -d':' -f1)
     18 rfkill unblock $ID
     19 (echo "power on"; sleep 0.1;
     20 echo "default-agent"; sleep 0.1;
     21 echo "pairable on"; sleep 0.1;
     22 echo "scan on"; sleep 0.1;
     23 echo "pair $HW"; sleep 0.5;
     24 echo "trust $HW"; sleep 0.5;
     25 echo "connect $HW"; sleep 5;
     26 echo quit; sleep 0.2) | bluetoothctl
     27