Jump to content

Fast Sound Input/Output Selector [Updated 13 Feb 2023]


Recommended Posts

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

  1. Directly uses system APIs to list and select sound devices, which makes it very fast and reliable
  2. No dependencies - no additional installs required
  3. Optionally add devices to a blocklist to hide them from results
  4. 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

 

Screenshot2023-02-13at12_25_32AM.png.230b8ab3d2abd7c5c138ef6143e003fc.png

 

Screenshot2023-02-13at12_26_11AM.png.b9cc37883daae0c0d490d4c1746254df.png

 

Edited by Mingwei
Update to v2.1.0
Link to comment
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.

Link to comment
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
  • Mingwei changed the title to Fast Sound Input/Output Selector [Updated 17 Nov]
  • Mingwei changed the title to Fast Sound Input/Output Selector [Updated 29 Nov]

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:

image.png.ab55136f84027b785417dad3c2cc52d0.png

 

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

@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 by Mingwei
Link to comment

@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 changed the title to Fast Sound Input/Output Selector [Updated 13 Dec]
  • 3 months later...
  • Mingwei changed the title to Fast Sound Input/Output Selector [Updated 14 Nov 2022]
  • 1 month later...

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

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:

image.thumb.png.d32b528ea395b0a3d67b791394b9774d.png

Edited by alfredpanda
Link to comment

@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
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 by davidraviv
Link to comment
  • 5 weeks later...
  • Mingwei changed the title to Fast Sound Input/Output Selector [Updated 13 Feb 2023]

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...