Skip to content

Instantly share code, notes, and snippets.

@ayarse
Last active December 10, 2020 00:55
Show Gist options
  • Save ayarse/9528005ae636523ed2f574b9e01e1999 to your computer and use it in GitHub Desktop.
Save ayarse/9528005ae636523ed2f574b9e01e1999 to your computer and use it in GitHub Desktop.
My QCY bluetooth headphones keep connecting to my mbp in Slave mode for some reason macOS has issues playing audio when in slave mode. Once disconnected the device reconnects in Master mode. This Hammerspoon script watches audio device events and uses blueutil (toy/blueutil) to quickly disconnect and reconnect the device if its in slave mode.
hs.audiodevice.watcher.setCallback(function(evt)
if evt == "sOut" or evt == "dOut" then
hs.eventtap.keyStroke({}, 'F8')
end
qcyMac = "00-00-00-00-00-00"
devices = hs.execute("/usr/local/bin/blueutil --paired | grep -i qcy | grep -i slave");
if(string.len(devices) > 0) then
hs.execute("/usr/local/bin/blueutil --disconnect " .. qcyMac)
hs.execute("/usr/local/bin/blueutil --connect " .. qcyMac)
end
end)
hs.audiodevice.watcher.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment