Advertisement
Guest User

a little bluetooth script

a guest
Oct 19th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. input=$1
  4. MAC=[insert mac address here]
  5.  
  6. turn_on() {
  7.   local output
  8.   local len
  9.   local userinput
  10.  
  11.   coproc bluetoothctl
  12.  
  13.   echo "scan on" >&${COPROC[1]}
  14.   sleep 3
  15.   pair_bluetooth
  16.   connect_bluetooth
  17.  
  18.   echo "exit" >&${COPROC[1]}
  19. }
  20. pair_bluetooth() {
  21.   echo "pair ${MAC}" >&${COPROC[1]}
  22.   echo "paired (y/n)?  "
  23.   read userinput
  24.  
  25.   while [[ ${userinput} == "n" ]]; do
  26.     echo "pair ${MAC}" >&${COPROC[1]}
  27.     echo "paired (y/n)?  "
  28.     read userinput
  29.   done
  30. }
  31. connect_bluetooth() {
  32.   echo "connect ${MAC}" >&${COPROC[1]}
  33.   echo "connected (y/n)?  "
  34.   read userinput
  35.  
  36.   while [[ ${userinput} == "n" ]]; do
  37.     echo "connect ${MAC}" >&${COPROC[1]}
  38.     echo "connected (y/n)?  "
  39.     read userinput
  40.   done
  41. }
  42.  
  43.  
  44. turn_off() {
  45.   coproc bluetoothctl
  46.  
  47.   echo "disconnect ${MAC}" >&${COPROC[1]}
  48.   sleep 2
  49.   echo "remove ${MAC}" >&${COPROC[1]}
  50.   sleep 1
  51.  
  52.   echo "exit" >&${COPROC[1]}
  53. }
  54.  
  55.  
  56. if [[ ${input} == "on" ]]; then
  57.   turn_on
  58. elif [[ ${input} == "off" ]]; then
  59.   turn_off
  60. else
  61.   printf "Usage:  pairbuds.sh [on | off]\n"
  62. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement