Jump to content

Fast Sound Input/Output Selector [Updated 13 Dec]


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++ and it runs much faster, so I'm sharing it here in case anyone's interested. 

 

Dependencies

  1. switchaudio-osx
  2. [optional] terminal-notifier

 

Optionally configure workflow environmental variables:

  1. Set `NOTIFIER` to 'terminal-notifier'
    • This replaces the alfred notification banner with one that looks like it's from System Preferences
    • If setting `NOTIFIER` to 'terminal-notifier' doesn't work, try setting it to the path of `terminal-notifier`
    • Use the terminal command `which terminal-notifier` to find the path
  2. Set `CMDPATH` to the path of `switchaudio-osx`
    • Try this if the workflow doesn't work out of the box
    • Use the terminal command `which switchaudiosource` to find the path

 

Optionally blocklist specific devices:

  • Type `sound:blocklist <full name of device>` into Alfred
    • For example, `sound:blocklist zoomaudiodevice`
  • Alternatively, press shift+return while a device is selected to hide it from future results

 

Changelog

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

I'm very much a beginner at c++, so any criticism / guidance would be much appreciated.

 

Screenshot

1769477193_Screenshot2021-11-17at12_57_49AM.thumb.png.90e9abd0a46d5804132da61902bb6593.png

Edited by Mingwei
Update to v1.1.1
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]

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...