Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active April 15, 2019 00:57
Show Gist options
  • Save J3698/ff094945fe3a235fc0c46872ad10abe1 to your computer and use it in GitHub Desktop.
Save J3698/ff094945fe3a235fc0c46872ad10abe1 to your computer and use it in GitHub Desktop.
Automatically accept incoming bluetooth connections
#!/usr/bin/env bash
amixer -c 0 cset numid=3
coproc stdbuf -oL bluetoothctl
sleep 7
sudo -u pi pulseaudio --start
echo -e "pairable on\n" >& ${COPROC[1]}
echo -e "discoverable on\n" >& ${COPROC[1]}
echo -e "agent NoInputNoOutput\n" >& ${COPROC[1]}
echo -e "default-agent" >& ${COPROC[1]}
while true
do
read -ru ${COPROC[0]} line
echo $line
if [[ "$line" == *"Paired: yes"* ]]
then
mac=`echo $line | awk '{print $(NF-2)}'`
echo $mac
echo -e "trust $mac" >& ${COPROC[1]}
echo -e "connect $mac" >& ${COPROC[1]}
elif [[ "$line" == *"Discoverable: no"* ]]
then
echo -e "discoverable on\n" >& ${COPROC[1]}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment