23

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?

Matthias Braun
  • 1,162
  • 1
  • 17
  • 29
Tiwenty
  • 331
  • 1
  • 2
  • 6

6 Answers6

14

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
  • 3
niveau0
  • 141
  • 1
  • 2
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
Ôrel
  • 151
  • 1
  • 3
2

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

ewen-lbh
  • 103
  • 4
  • 1
    Welcome to Super User! Would you mind explaining how that would help the person who asked the question? – Registered User May 10 '20 at 23:08
  • 2
    I get `Missing device address arguments` – Swedgin Sep 21 '20 at 18:13
  • 2
    @Swedgin this means you have no connected devices. – joshpetit Jan 20 '21 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 02 '21 at 06:56
  • 1
    @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 '21 at 16:08
2

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.

pallxk
  • 324
  • 1
  • 5
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.

Casey Jones
  • 110
  • 9
9 Guy
  • 105
  • 1
  • 8
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