Check Bluetooth Device Status

us flag

Is there any method to check whether there is any Bluetooth device connected to my Ubuntu 22.04? I know that the drop-down in the top bar or Bluetooth Settings will help. I am actually trying to fetch it through a Python file or a .sh file and display an indicator so that I can add some notification-window like indicator. Thanks.

Edit 1:

I have this code from here that helps a lot. I just need some method to add a dismissible indicator that reminds me that a Bluetooth device is connected. I need this to remind me to disconnect the device before turning off the computer.

import pydbus

bus = pydbus.SystemBus()

adapter = bus.get('org.bluez', '/org/bluez/hci0')
mngr = bus.get('org.bluez', '/')

def list_connected_devices():
    mngd_objs = mngr.GetManagedObjects()
    for path in mngd_objs:
        con_state = mngd_objs[path].get('org.bluez.Device1', {}).get('Connected', False)
        if con_state:
            addr = mngd_objs[path].get('org.bluez.Device1', {}).get('Address')
            name = mngd_objs[path].get('org.bluez.Device1', {}).get('Name')
            print(f'Device {name} [{addr}] is connected')

if __name__ == '__main__':
gt flag
sudo service bluetooth status

if you entered this command you will see the status of bluetooth like this to know bluetooth connectivity

○ bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor pre>
     Active: inactive (dead)
       Docs: man:bluetoothd(8)

or you can use application like enter image description here

I sit in a Tesla and translated this thread with Ai:


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.