Is there a way to program a computer audio output switcher? Go from source-nexus (routed thru pro tools) or Apogee Maestro going to an external mixer?
- Christian Scheuer @chrscheuer2020-05-15 14:06:24.391Z
You can do something like this:
var volumeMenu = sf.ui.app('com.apple.systemuiserver').getElement("AXMenuBar").children.whoseDescription.startsWith('volume ').first; volumeMenu.popupMenuSelect({ isOption: true, menuPath: ['Headphones'] });
- MMatt Friedman @Matt_Friedman
This is awesome but do you have a Monterey update to this script? better yet maybe some logic so it can work in both Monterey and older OS?
It looks like in Monterey, it's now the control center.
sf.ui.app("com.apple.controlcenter").getElement("AXExtrasMenuBar")
But I can't get further than that so I can't figure out how to make it select the desired output.
Thanks
- In reply tochrscheuer⬆:
Nathan Salefski @nathansalefski
Bumping this. I've found this here and it seems to work however it seems a bit clunkier than need be. https://apple.stackexchange.com/questions/217148/using-apple-script-to-manage-sound-output-selection
sf.system.execAppleScript({ script: `set outputA to 2 --change this to the actual 'line number' of your first desired output set outputB to 3 --change this to the actual 'line number' of your second desired output tell application "System Preferences" activate set current pane to pane "com.apple.preference.sound" end tell tell application "System Events" tell application process "System Preferences" repeat until exists tab group 1 of window "Sound" end repeat tell tab group 1 of window "Sound" click radio button "Output" if (selected of row outputA of table 1 of scroll area 1) then set selected of row outputB of table 1 of scroll area 1 to true else set selected of row outputA of table 1 of scroll area 1 to true end if end tell end tell end tell tell application "System Preferences" to quit` });
- In reply tochrscheuer⬆:
Nathan Salefski @nathansalefski
I have also made the smallest measurable amount of progress with Apple Scripts lol. I can open the volume panel but cannot for the life of me figure out how to select an option
sf.system.execAppleScript({ script: `tell application "System Events" tell its application process "Control Center" click menu bar item "Sound" of menu bar 1 end tell end tell` });
- JIn reply toJonathan_Grossman⬆:Jonathan Grossman @Jonathan_Grossman
Amazing - so now if I want to toggle between these with one button, how far off am I with this script....
globalState.inputswitcherScriptState = !globalState.inputswitcherScriptState;
if (globalState.inputswitcherScriptState) {
(var volumeMenu = sf.ui.app('com.apple.systemuiserver').getElement("AXMenuBar").children.whoseDescription.startsWith('volume ').first;
volumeMenu.popupMenuSelect({
isOption: true,
menuPath: ['Duet USB']);
} else {
(var volumeMenu = sf.ui.app('com.apple.systemuiserver').getElement("AXMenuBar").children.whoseDescription.startsWith('volume ').first;
volumeMenu.popupMenuSelect({
isOption: true,
menuPath: ['Source-Connect']);
}- MMartin Pavey @Martin_Pavey
Hi There,
I'm trying to do a similar thing here.
Did you ever get this Core Audio toggle script to work?
This one doesn't seem to work for me.
Christian's original script works but the one button toggleing (which would be great) doesn't.
Thanks- JJonathan Grossman @Jonathan_Grossman
I did! Will send a script when I get in the studio a bit later.
- In reply toMartin_Pavey⬆:JJonathan Grossman @Jonathan_Grossman
Hi Martin:
here's the code I use. Sorry it took another day!
const itemsToSwitch = ['ONEv2', 'Source-Nexus']; var volumeMenu = sf.ui.app('com.apple.systemuiserver').getElement("AXMenuBar").children.whoseDescription.startsWith('volume ').first; volumeMenu.popupMenuSelect({ menuSelector: menuItems => { const candidates = menuItems.filter(mi => itemsToSwitch.indexOf(mi.names[0]) >= 0); const selectedItem = candidates.map((menuItem, index) => ({ menuItem, index })).filter(m => m.menuItem.element.isMenuChecked)[0]; const oldIndex = selectedItem ? selectedItem.index : -1; let newIndex = oldIndex + 1; if (newIndex >= candidates.length) newIndex = 0; return candidates[newIndex]; }, });
- MMartin Pavey @Martin_Pavey
Wow!
Thanks so much Jonathan, it works perfectly.
I owe you a virtual beer.
Cheers
Martin- JJonathan Grossman @Jonathan_Grossman
haha! Can't take credit...I'm only the messenger. that's from the wonderful coded mind of Christian
- MMartin Pavey @Martin_Pavey
Ha! Nice one.
Beers all round then!
- In reply toJonathan_Grossman⬆:Ben Rubin @Ben_Rubin
Thanks so much for this one!!!
- In reply toJonathan_Grossman⬆:Ben Rubin @Ben_Rubin
jumping back on this thread, i'm realizing that because I hide my menu bar by default, this script will often fail. Does anyone know how to force the OS to show the menu bar?
thanks
ben - PIn reply toJonathan_Grossman⬆:@pepsin
Has anyone gotten this command to work on Monterey? I'm currently on 12.3.
Thanks for your time!
- M
Christian Scheuer @chrscheuer2022-10-01 05:40:43.990Z
I tried a few things and I could locate the menu button (I don't remember the code right now unfortunately) but I couldn't get the menu items to be found.
It's possible we should look at this as a feature request to change audio input/output settings directly via a SF action instead of relying on these menus.- AAlexander Jenkins @Alexander_Jenkins
Hi all, please let me know if I'm in the wrong place for this. I'm trying to switch between my Focusrite Red8Pre and Dante Virtual Sound Card using button(s) on my Stream Deck. I need the Red8Pre for all recording/mixing and the Dante Virtual Sound card for Atmos 7.1.4 playback from Apple Music through the Dante Virtual Soundcard into the Dante Controller into the RedNet software. I'm currently switching using the "Sound" menu currently showing up in the menu items, or I open Audio/Midi setup and change it there. I've tried using Christian's solution on post #6 (adding the changes suggested for use in Monterey) but alas I have little to almost no clue how to code. My two devices are showing in the "Output" menu (in the "Sound" Menu as as "Focusrite Thunderbolt" and "Dante Virtual Soundcard". Is it possible to toggle between these two devices using a button on a Stream Deck by creating a button(s) in SoundFlow? Thanks! If I'm out of my depth here I'll accept that. If I'm only a few tweaks away from the solution I appreciate any help someone would be willing to offer. Thanks! Alex J
- In reply tochrscheuer⬆:
Nathan Salefski @nathansalefski
Hey @chrscheuer any update on this one?
- In reply tonathansalefski⬆:
Christian Scheuer @chrscheuer2023-12-06 11:42:02.298Z
You can use something like this:
https://github.com/deweller/switchaudio-osxInstall it first via Homebrew, then it should be easy to run to switch audio outputs in Terminal.
Once you know how to do it in Terminal, you can then write a SF script that runs a Terminal command to do it for you.