Every time I wake up PC from sleep I have to go to bluetooth settings -> select device -> enable connection to get sound on bluetooth speakers (Anker Soundcore). Bluetooth came with MBO and drivers were working out of the box after PopOS install.

I hope there is a command I can use instead of clicking in the GUI. Anyone know a command I could use?

[SOLUTION]

Using this command (with bluetooth speaker MAC address):

bluetoothctl connect A4:77:58:0A:DF:F1

[SOLUTION]

Bonus question: I was thinking I could map that command to a keyboard shortcut (like CTRL+ALT+B). What is the best way (or app) to accomplish this? I believe I could google this part quickly, but happy to hear suggestions anyway

[SOLUTION]

It’s possible with PopOS: Settings -> Keyboard -> Keaboard Shortcuts -> Custom Shortcuts

[SOLUTION]

<3

  • Para_lyzed@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    4 months ago

    Well, for your particular case, you’d make a script, and a service to run that script on boot. Once the service starts, it will keep itself alive.

    Here’s the script:

    bluetooth-reconnect.sh

    #!/bin/bash
    
    dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
      while read x; do
        if echo $x | grep -q "boolean false"
          bluetoothctl connect A1:11:22:3A:CD:F1
        fi
      done
    

    You’d place this script somewhere that has system execution privilege (if your distro uses SELinux). I will use the directory /usr/scripts/ for example purposes (note that you will have to create this folder). Make sure to mark it executable with chmod +x /usr/scripts/bluetooth-reconnect.sh

    You’d then write a service to start at boot, just really barebones and simple:

    bluetooth-reconnect.service

    [Unit]
    Description=Reconnect Bluetooth after waking from sleep
    After=default.target
    
    [Service]
    Type=simple
    ExecStart=/usr/scripts/bluetooth-reconnect.sh
    
    [Install]
    WantedBy=multi-user.target
    

    Move the service into /etc/systemd/system/ (filepath should be /etc/systemd/system/bluetooth-reconnect.service), and enable it and start it:

    sudo systemctl enable bluetooth-reconnect.service && sudo systemctl start bluetooth-reconnect.service

    And you should be good to go. At least assuming your distro doesn’t have some specific quirk, which I wouldn’t be able to help you with unless I knew what distro you run. Granted, this is my adaptation of what I saw in the linked forum and my own experience with services, I haven’t actually tested this. But even if it has an issue, this will get you 90% of the way there, and there’s a good chance it just works if the forum answers work for your distro.

    • rambos@lemm.eeOP
      link
      fedilink
      arrow-up
      1
      ·
      4 months ago

      Thank you a lot mate for explaining in detail. I will deffo go that route