Skip to content

Instantly share code, notes, and snippets.

@mlegner
Created June 20, 2018 14:21
Show Gist options
  • Save mlegner/17a992baa2de8c83b36ca08aa7dd9938 to your computer and use it in GitHub Desktop.
Save mlegner/17a992baa2de8c83b36ca08aa7dd9938 to your computer and use it in GitHub Desktop.
Short script that connects properly to my bluetooth headphones and enables A2DP mode
#!/bin/bash
# Connect to the bluetooth headphones properly and enable A2DP
mac="AA:AA:AA:AA:AA:AA" # the MAC address of the bluetooth headphones
cardname="bluez_card.AA_AA_AA_AA_AA_AA" # the audio-card name associated with the bluetooth headphones
timeout=5 # timeout for connecting
coproc bluetoothctl
echo -e "connect $mac" >&${COPROC[1]}
timeout $timeout grep -q "ServicesResolved: yes" <&${COPROC[0]} || echo -e "connect $mac" >&${COPROC[1]}
echo -e "exit" >&${COPROC[1]}
echo Connecting to card $cardname
pacmd set-card-profile $cardname off
pacmd set-card-profile $cardname a2dp_sink
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment