25

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?

6 Answers 6

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"
5

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
3

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.

2

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

5
  • 1
    Welcome to Super User! Would you mind explaining how that would help the person who asked the question? May 10, 2020 at 23:08
  • 2
    I get Missing device address arguments
    – Swedgin
    Sep 21, 2020 at 18:13
  • 2
    @Swedgin this means you have no connected devices.
    – joshpetit
    Jan 20, 2021 at 18:07
  • I see my headphones listed when i run bluetoothctl paired-devices -- but when I run bluetoothctl info I still get the error Missing device address argument...
    – Carl Walsh
    Mar 2, 2021 at 6:56
  • 2
    @CarlWalsh, the error tells you exactly what you're missing: bluetoothctl info gives information about a single device, thus you need to tell it the MAC address of the device you want to get information about.
    – ewen-lbh
    Aug 18, 2021 at 16:08
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.

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .