Automating Bluetooth Profile switching thanks to Copilot Chat

A task I completed that I wouldn't have (or at least, not without putting several hours into it) without Generative AI:

I use an Arch-based Linux distro called Endeavour OS. It's a great OS, but lately, I've been having this issue where my computer wasn't recognizing my Bluetooth headset's mic. The only way to have calls with a mic was to plug in a wired headset.

After a bit of research, I found out about Bluetooth profiles. Briefly, a typical Bluetooth headset with a mic can operate in two profiles:

  1. A2DP: High audio quality, but no mic

  2. HFP/HSP: Low audio quality, but can use mic for calls.

Generally, an OS switches between these profiles depending on the task. When on a call, HFP/HSP is used. During music playback, A2DP is used. My computer wasn't switching between them, and that's why I wasn't able to use the mic.

I could change the profile either through the command line or through the GUI console. However, this was rather cumbersome to do before and after every call. So, I resorted to writing a script that can be run to switch the profiles. This though, would require extracting a lot of information from the console, and quite a bit of grep commands.

Since I'm not that big of an expert in shell programming, I used Copilot Chat from GitHub. I supplied it output of pactl list cards, and from there with a little bit of back and forth, we arrived at a script that can toggle profiles for any of my headsets.

Since I use KDE, I easily created a desktop icon with a dedicated keyboard shortcut and put it in my panel for easy access. Now until I find a permanent solution, this works wonderfully.

Without tools like ChatGPT or GitHub Copilot Chat, I would've never written the script and kept using the console to switch between profiles. Admittedly, I'd have gotten rather fast at it, but this wasn't the best solution.

This supplants my belief that Generative AI tools can augment developer productivity, by allowing us to venture into areas where we otherwise wouldn't. It's not like Copilot gave me the right commands in the first go. It took about 30 minutes of back and forth and someone with the knowledge of operating the terminal to arrive at the correct script, but it's a nice start!

I see this partnership becoming only productive in the future. Excited to see what it holds.

PS: The script in question: