I'm trying to get a list of connected Bluetooth devices via the command line on Kubuntu.
When I launch bluetoothctl, it defaults to the latest connected device, and I need to disconnect it to display the other one.
Is there a way to list the connected Bluetooth devices?
5 Answers
Here's a fish-shell one-liner (see below for bash)
bluetoothctl devices | cut -f2 -d' ' | while read uuid; bluetoothctl info $uuid; end|grep -e "Device\|Connected\|Name"bash one-liner:
bluetoothctl devices | cut -f2 -d' ' | while read uuid; do bluetoothctl info $uuid; done|grep -e "Device\|Connected\|Name" You can list paired devices with bluetoothctl paired-devices
From this list you can get info for each device with bluetoothctl infoOn the info you have the Connected status.
So loop on each devices grep for Connected: yes if so display the name:
bluetoothctl paired-devices | cut -f2 -d' '|
while read -r uuid
do info=`bluetoothctl info $uuid` if echo "$info" | grep -q "Connected: yes"; then echo "$info" | grep "Name" fi
done This may help: sudo bluetoothctl info MAC-ADDRESS-OF-DEVICE
After running sudo bluetoothctl...
you can type paired-devices to see a list of paired devices
or list to see a list of currently connected controllers
you can also type info to see info about each device.
Each command here supports tab completion of MAC addresses.
I use this to display the currently connected device in my Swaybar:
bluetoothctl devices | cut -f2 -d' ' | while read uuid; do bluetoothctl info $uuid; done | grep -e "Name\|Connected: yes" | grep -B1 "yes" | head -n 1 | cut -d\ -f2-Breakdown:
bluetoothctl devices
# List all devices
cut -f2 -d' '
# Cut out the second column containing the MAC address
while read uuid; do bluetoothctl info $uuid; done
# For each MAC address call bluetoothctl info
grep -e "Name\|Connected: yes"
# Find all lines that have either name or Connected: yes
grep -B1 "yes"
# Find the line with yes and the line before that line
head -n 1
# Return the last line
cut -d\ -f2-
# Return the second column and all other columns for the device name