26

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?

Tiwenty
  • 361

6 Answers6

18

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"
Lincoln
  • 103
niveau0
  • 181
  • 1
  • 2
7

You can list paired devices with bluetoothctl paired-devices

From this list you can get info for each device with bluetoothctl info On 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
Ôrel
  • 171
6

As of bluez/bluetoothctl 5.65 (bluetoothctl --version), we can use bluetoothctl devices Connected (Capitalized C) to list connected bluetooth devices. For example:

$ bluetoothctl devices Connected
Device AA:BB:CC:DD:EE:FF MY-DEVICE-NAME

If you care about paired devices, use bluetoothctl devices Paired for bluez/bluetoothctl version >= 5.65, or bluetoothctl paired-devices for bluez/bluetoothctl < 5.65.

Xiangkun
  • 374
3

This may help: sudo bluetoothctl info MAC-ADDRESS-OF-DEVICE

Gwenn
  • 105
2

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

1

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.

9 Guy
  • 205
  • 2
  • 8