A better (?) way of updating audio output #782
pattydaone
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I've recently been messing with sketchybar for the first time, and ran into an infuriating issue. I have a widget which is subscribed to com.bluetooth.status.updates, and calls switchaudio-osx to query audio output device. The point is to show whether my output device is my airpods or my speakers. The problem was that, sometimes, something would happen, I would get literally thousands of switchaudio processes trying to run, as well as dozens of lua processes, which would slow my computer effectively to nothing. I tracked the problem down to the
AudioObjectGetPropertyDatain apples api, which would just.. hang, sometimes, when called. I have no idea why (a small amount of debugging led me to an error along the lines ofAddInstanceForFactory: No factory registered for idbut I don't have a clue what that means and I'm in no way knowledgeable enough to even begin to try and figure it out), I don't even know how to reliably reproduce this problem. I figure since no one here has reported such a problem, it must be a tahoe bug (I'm on the latest public version of macos).The way I "solved" this was by stealing the relevant functions from switchaudio-osx for querying device id and device name, and then writing a helper script to interface with sketchybar in c. I say "solved" because it doesn't get around the issue of that function hanging, it still calls it, but instead the helper program queries every second, if the output device changed, it triggers an event. Thus, the helper program is executed once and, should the function call hang, more instances wont be spawned, it'll just hang. Annoying, yes, because now I have to restart the bar, but its far less annoying than my laptop slowing to a crawl due to thousands of instances of something being spawned.
Also, since it supplies its own event and doesn't rely on bluetooth events, audio output changes through usbc or 3.5mm jack will also be detected, thus expanding the functionality of the script.
I doubt this is a particularly great solution, to be honest I just wanted to share it with anyone, as I'm pretty happy with it for now.
I also doubt anyone will be particularly interested in the code (most of it isn't even mine), but if so let me know and I'll supply the files.
Thanks for reading!
Beta Was this translation helpful? Give feedback.
All reactions