Skip to content

Instantly share code, notes, and snippets.

@heinrich-ulbricht
Created June 28, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heinrich-ulbricht/dfaff95d36cee99babaa50377c6bd568 to your computer and use it in GitHub Desktop.
Save heinrich-ulbricht/dfaff95d36cee99babaa50377c6bd568 to your computer and use it in GitHub Desktop.
Set up bluetooth headphones with Qubes OS
#!/bin/bash
# original source from https://m7i.org/tips/qubes-VM-bluetooth-audio/
# fixed calls to qvm-usb and replaced bluetooth-assistant with bluetoothctl (see https://github.com/blueman-project/blueman/issues/1560)
# remember preparing AppVM template: sudo apt-get install qubes-usb-proxy bluez blueman pulseaudio-module-bluetooth pavucontrol
set -o errexit
set -o nounset
# Customize the following value by the USB device ID (look in qvm-usb --list)
export usb_device="Broadcom_Corp_BCM20702A0_5CF370995B89";
# Customize the following value with the bluetooth headphones' MAC address
export headphones="9C:19:C2:FC:AD:5F" # Aukey BT headset
# export headphones="9C:19:C2:9B:BA:27" # Xoaomi BT headset
if [ $# -ne 1 ]; then
echo -en "Usage: bluetooth-audio VM-name\n\tStarts the bluetooth audio for the VM specified\n" >&2
exit 1
else
export VM="$1";
# Looks for the USB device
qvm-usb list | grep -F "$usb_device" >/dev/null || {
echo "Error: device $usb_device is not connected." >&2
exit 1;
}
# Checks if the device is already connected to the target VM
if qvm-usb list | grep -F "$usb_device" | grep -F " $VM" >/dev/null; then
echo "Device $usb_device is already connected to $VM, not doing anything."
exit 1;
else
# Finds the sys-usb's assigned name for the USB device
assignment="$(qvm-usb list | grep "$usb_device" | awk '{ print $1; }')";
echo "Connecting $assignment to $VM...";
qvm-usb attach "$VM" "$assignment" || {
echo "Could not attach the device $usb_device to $VM." >&2
exit 1;
}
fi;
echo "Reconfiguring pulseaudio for bluetooth audio in $VM..."
qvm-run "$VM" -- "killall pulseaudio"
qvm-run "$VM" -- "pulseaudio --start"
qvm-run "$VM" -- "bluetoothctl connect ${headphones}"
qvm-run "$VM" -- "pavucontrol"
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment