Mingwei Posted November 16, 2021 Share Posted November 16, 2021 (edited) There are probably quite a few sound device selector script filters out there, but the ones I've come across are mostly written in applescript. I rewrote my own in C++ Swift and it runs much faster, so I'm sharing it here in case anyone's interested. Features Directly uses system APIs to list and select sound devices, which makes it very fast and reliable No dependencies - no additional installs required Optionally add devices to a blocklist to hide them from results Optionally disable device selected notifications Installation note On initial run, you'll see a pop-up window that says something like: "sound_filter" / "sound_selector" cannot be opened because the developer cannot be verified. This is a macOS security feature that blocks execution of non-codesigned binaries You're seeing it because this workflow uses pre-compiled binaries rather than interpreted code (e.g. Python) I can't codesign those binaries because I'd need an Apple developer account and that costs money The security risk is that you have to trust that I'm not doing malicious stuff with the binaries (I'm not) (This workflow is open-source and you can compile the binaries yourself, in which case all this is moot, but that's very inconvenient) You have to bypass this security feature to use this workflow. To do so, follow the instructions here. Changelog v2.1.0 Fixed: Icon visibility in light mode (icons automatically change with appearance settings) New: Prettier notifications no longer require terminal-notifier v2.0.0 New: `switchaudio-osx` no longer required New: Significantly faster loading speeds New: Icons now indicate whether a device is selected New: Makes use of Alfred 5 user configuration panel to simplify setup v1.1.1 Fixed: Cannot parse switchaudio-osx JSON in some cases v1.1.0 Added: User-configurable device blocklist (see feature request) Fixed: Issue with user-set path for switchaudio-osx v1.0.2 Minor performance optimisations v1.0.1 Added: In most cases, users no longer need to specify the path of switchaudio-osx (see relevant comment) Fixed: Missing icon images in terminal-notifier notification Download | Source Screenshots Edited February 12 by Mingwei Update to v2.1.0 Floating.Point, xgo and Saez 3 Link to comment
vitor Posted November 16, 2021 Share Posted November 16, 2021 10 minutes ago, Mingwei said: Set `CMDPATH` to the path of `switchaudio-osx` This could be made optional (and then they all would be!) by setting PATH to /opt/homebrew/bin:/usr/local/bin:${PATH} in your code. It would cover the majority of installs, especially if done via Homebrew which you already recommend. Then the variable could be used for the user to set an extra PATH entry if needed. Mingwei 1 Link to comment
Mingwei Posted November 16, 2021 Author Share Posted November 16, 2021 4 minutes ago, vitor said: This could be made optional (and then they all would be!) by setting PATH to /opt/homebrew/bin:/usr/local/bin:${PATH} in your code. It would cover the majority of installs, especially if done via Homebrew which you already recommend. Then the variable could be used for the user to set an extra PATH entry if needed. Thanks for the tip! Will update it Link to comment
Slatts Posted November 16, 2021 Share Posted November 16, 2021 The audio switcher I was using broke under Monterey. This is great Mingwei, thank you! Mingwei 1 Link to comment
Floating.Point Posted November 25, 2021 Share Posted November 25, 2021 Hi Mingwei, Thank you for putting together this very helpful workflow. Wondering if you might take under consideration a feature request? It would be really nice if certain devices could be hidden/ignored in the list of options. Cheers! Link to comment
Mingwei Posted November 25, 2021 Author Share Posted November 25, 2021 @Floating.Point will look into it, should be easy to add. Floating.Point 1 Link to comment
xgo Posted December 1, 2021 Share Posted December 1, 2021 This looks super useful, I just found myself needing a workflow like this and thought of your recent post and installed. I do have switchaudio installed (today, v1.1.0 for Monterey) and this workflow "disappears" a split second after the Loading prompt appear. Debugging shows an empty error without much context - any thoughts? See screenshot of the erroring Script Filter: I tried looking into the sound_filter cpp source but I have no clue what I'm doing and can't get anything to compile. Link to comment
Mingwei Posted December 2, 2021 Author Share Posted December 2, 2021 (edited) @xgo Error code 2 in the log means the script filter couldn't parse the json coming from switchaudio-osx. I think I've identified the problem, but could I see the output you receive from switchaudio-osx to be sure? Run this in your terminal and paste the output here: switchaudiosource -af json If you have some time, do you mind also downloading v1.0.2 of the workflow and trying that to see if it works? I made some changes in the new version unrelated to the new blocklist feature that could be causing the problem. Edited December 2, 2021 by Mingwei Link to comment
xgo Posted December 2, 2021 Share Posted December 2, 2021 @Mingwei thanks for the quick turnaround. Can confirm that 1.0.2 works as expected. If I trump it back with latest (w/ blocklist feature) I get back into the problems. Here's the output from my -af call - it's probably a decent test case since I have so many things connected to my work laptop (monitor w/ speakers, USB speakers, Jabra headset) {"name": "USB2.0 Device", "type": "input", "id": "95", "uid": "AppleUSBAudioEngine:Generic:USB2.0 Device:20170726905959:2"} {"name": "ThinkPad Thunderbolt 3 Dock USB Audio", "type": "input", "id": "86", "uid": "AppleUSBAudioEngine:Lenovo:ThinkPad Thunderbolt 3 Dock USB Audio:000000000000:1"} {"name": "Jabra Link 370", "type": "input", "id": "111", "uid": "AppleUSBAudioEngine:Unknown Manufacturer:Jabra Link 370:70BF9247FC7A:2"} {"name": "Logitech BRIO", "type": "input", "id": "103", "uid": "AppleUSBAudioEngine:Unknown Manufacturer:Logitech BRIO:A34C02B9:4"} {"name": "MacBook Pro Microphone", "type": "input", "id": "81", "uid": "BuiltInMicrophoneDevice"} {"name": "PHL 346B1C", "type": "output", "id": "115", "uid": "AppleGFXHDAEngineOutputDP:f803:0:{0C41-093E-000070EB}"} {"name": "USB2.0 Device", "type": "output", "id": "99", "uid": "AppleUSBAudioEngine:Generic:USB2.0 Device:20170726905959:1"} {"name": "ThinkPad Thunderbolt 3 Dock USB Audio", "type": "output", "id": "90", "uid": "AppleUSBAudioEngine:Lenovo:ThinkPad Thunderbolt 3 Dock USB Audio:000000000000:2"} {"name": "Jabra Link 370", "type": "output", "id": "107", "uid": "AppleUSBAudioEngine:Unknown Manufacturer:Jabra Link 370:70BF9247FC7A:1"} {"name": "MacBook Pro Speakers", "type": "output", "id": "74", "uid": "BuiltInSpeakerDevice"} By the way, Github release says 1.1.0 but Alfred lists as 1.0.3 - might be worth aligning those! Lastly, switchaudio doesn't seem to support airplay outputs, but there's been a few discussions on how to enable it, even on another Alfred workflow. I personally would not use this, but might be worth keeping in a backlog https://github.com/deweller/switchaudio-osx/issues/9 Link to comment
Mingwei Posted December 3, 2021 Author Share Posted December 3, 2021 @xgo could you install this pre-release and let me know if it works? Thanks for the tip on airplay! I don't use airplay either so I'd have trouble testing stuff, but I want to try replacing switchaudio-osx with macOS APIs at some point so I might be able to look into it then. xgo 1 Link to comment
xgo Posted December 9, 2021 Share Posted December 9, 2021 @Mingwei sorry for the delay - this version works perfect for me. Thanks so much, loving this! Mingwei 1 Link to comment
noelneb Posted March 29, 2022 Share Posted March 29, 2022 Hi MingWei. I got a pretty similar issue with xgo. After installed i got this error immediately after the workflow went disappeared. Tried both v.1.1.1 and v.1.0.2 but to no avail. Thanks. Link to comment
vitor Posted March 29, 2022 Share Posted March 29, 2022 @noelneb See the awgo wiki for why that happens and how to go around it. Link to comment
noelneb Posted March 30, 2022 Share Posted March 30, 2022 10 hours ago, vitor said: @noelneb See the awgo wiki for why that happens and how to go around it. It worked! Thanks so much @vitor Link to comment
davidraviv Posted December 19, 2022 Share Posted December 19, 2022 Hello @Mingwei, When trying to execute the workflow I get an exception. After selecting "Switch Sound Devices" I get the following in the debug console: [11:20:10.398] Switch Sound Devices[Script Filter] Queuing argument '(null)' [11:20:10.412] Switch Sound Devices[Script Filter] Script with argv '(null)' finished [11:20:10.420] ERROR: Switch Sound Devices[Script Filter] Code 134: dyld[14716]: Symbol not found: (_$s10Foundation11JSONEncoderC6encodeyAA4DataVxKSERzlFTj) Referenced from: '/Users/david/Library/CloudStorage/GoogleDrive/My Drive/setup/config/Alfred.alfredpreferences/workflows/user.workflow.6C1A49F3-FDC5-4A82-9C8D-464F5C8CF805/sound-filter' Expected in: '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation' I did followed the awgo wiki to solve the permission issue, and it worked. I didn't set any configuration. I don't have the following installed: terminal-notifier switchaudio-osx I'm using: Monterey / Alfred 5 / Switch.Sound.Devices 2.0.0 Thanks! Link to comment
alfredpanda Posted December 22, 2022 Share Posted December 22, 2022 (edited) Thank you so much for this! This is just what I need. I have some Soundcore headphones that I like, but the multipoint functionality can be temperamental. I did however see the following message, so followed these instructions to manually open "sound-filter" when then worked. Quote "sound-filter" can't be opened because Apple cannot check it for malicious software. 2 suggestions: 1) Disabling notifications entirely. 2) I'd love to maybe change these icons so they work more universally across Alfred themes - they're a little hard to see: Edited December 22, 2022 by alfredpanda Link to comment
Mingwei Posted December 24, 2022 Author Share Posted December 24, 2022 @davidraviv That error message means there's probably some sort of issue with how frameworks are linked to the compiled binary. It's strange because I can't reproduce the error on my end. I'll play around with it and see if I can figure it out, though this might take a while as I'm busy with other stuff right now, and I'll probably need you to help me test it out. @alfredpanda very valid suggestions. I personally like the notifications, but you can easily disable them on your end by deleting the Post Notification action in the workflow (and deleting all lines after the first line in the Run Script action if you have terminal-notifier installed, but I'm guessing you don't). Realised I made icons that only really work in dark mode after releasing it haha, I've been meaning to do something about that for a while but haven't had the time. In the meantime you can change the icons by opening the workflow folder and replacing all icon images with identically named files of your choosing. I got those icons from SF Symbols so you could do the same to create light mode compatible versions. Link to comment
alfredpanda Posted December 24, 2022 Share Posted December 24, 2022 Thank you! I’m honestly so grateful you made this. For anyone using Soundcore headphones connected to a Mac and iPhone this is a must-have!! Link to comment
davidraviv Posted December 25, 2022 Share Posted December 25, 2022 (edited) On 12/24/2022 at 9:44 AM, Mingwei said: @davidraviv That error message means there's probably some sort of issue with how frameworks are linked to the compiled binary. It's strange because I can't reproduce the error on my end. I'll play around with it and see if I can figure it out, though this might take a while as I'm busy with other stuff right now, and I'll probably need you to help me test it out. @alfredpanda very valid suggestions. I personally like the notifications, but you can easily disable them on your end by deleting the Post Notification action in the workflow (and deleting all lines after the first line in the Run Script action if you have terminal-notifier installed, but I'm guessing you don't). Realised I made icons that only really work in dark mode after releasing it haha, I've been meaning to do something about that for a while but haven't had the time. In the meantime you can change the icons by opening the workflow folder and replacing all icon images with identically named files of your choosing. I got those icons from SF Symbols so you could do the same to create light mode compatible versions. Thanks @Mingwei for investing your time into it! Please let me know how can I help. Edited December 25, 2022 by davidraviv Link to comment
c0desurfer Posted December 26, 2022 Share Posted December 26, 2022 Very nice indeed, thanks. The sound device filter is not working for me. Link to comment
jeremycherfas Posted January 25 Share Posted January 25 Thank you very much for this. Works beautifully on Ventura. Link to comment
Mingwei Posted February 12 Author Share Posted February 12 @alfredpanda the latest version (updated in the main post) will automatically switch icons to match dark/light mode and adds a user setting for disabling notifications @davidraviv I think? It's a macOS version issue? Realised I've been compiling the previous versions for macOS 13 and above. I think it should work on your Monterey system now? Fingers crossed! I would ask for more info from you but the error log is pointing at something so basic (it can't find a built-in framework) that I don't know what else could be the issue. @c0desurfer Do let me know what device name you're trying to filter out so I can test it on my end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now