I just recently did something like that
Checkout my github repo under "desktop entries
It should be systemctl start bluetooth
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
I just recently did something like that
Checkout my github repo under "desktop entries
It should be systemctl start bluetooth
Thx! I could enable/disable bluetooth with your commands and that didn't solve my problem, but helped me google the right command. It is actually much simpler that I thought, I just had to find speakers MAC and I can use:
bluetoothctl connect A1:11:22:3A:CD:F1
Now working on mapping that to a key, cheers!
You could also run the command automatically every time your screen is unlocked depending on your DE. For instance, if you use GNOME, this will likely work
EDIT: see comment below for better solution
Thank you! I use GNOME, but this is kinda confusing tbh. I was also looking at this forum post where I should put a script in /lib/systemd/system-sleep/
. I should play around with that, but can't afford breaking system right now xD. Will try it soon, I might install separate OS just for testing
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.
Please don’t crucify me but is there a way to do this on windows ? I just have a handheld gaming console that came with windows and it’s setup just the way I want but would be nice if I can also connect to Bluetooth using command line so that I can map it to playnite and have it automatically connect to my headphones when launching a game. I did a lot of research and tried some stuff like “Bluetooth command line tools” which worked a bit but somehow caused a lot of instability and caused crashes so had to stop using it.
Probably, but this is not the place to ask if you want answers. This forum is for Linux discussion, not Windows, and while I could get this set up in Linux for you, I wouldn't even know where to start with Windows, as I haven't used it in a decade. You'll see a lot of the same with experienced Linux users here. Most of us will not be able to help you. I recommend you ask in a Windows forum instead, as you'll have a much greater chance of finding someone knowledgeable to help. Maybe there's a forum for Windows command line (or Powershell? I don't know what they're calling it these days).