I can’t get my Airpods Pro 2 to connect to Mavericks at all for any length of time, this has been driving me nuts for years! They’ll connect and play audio for a few seconds, then cut out, and I’ll have to re-pair to get any audio again.
i don't think macos allows l2cap connections (the protocol that airpods use), at least pybluez doesn't support that on macos which would've made making a simple script a lot simpler.
Check out AirBuddy for something that provides similar control in macOS. Closed source and costs money though. It doesn't need to rely on the reverse engineered protocol, and instead just calls out to macOS APIs to manipulate the Airpods. (I presume)