No internet connection
  1. Home
  2. How to

Select a setting in Mac Preferences

By Dan Israel @DanIsrael
    2023-12-06 00:41:14.654Z

    I'm trying to setup a button to toggle the Mac Sound Output between ProTools and Carbon Interface. I'm attempting to do this with a script but it is not working. Can you advise a better way to do this?

    Here is the code I'm using:
    //Calling command "System Preferences_OPEN APP" from package "Applications" (installed from user/pkg/version "iDVCzKgxCsRMTzLbu8IWNKxYpvh1/ckag2danb00012e101wex822n/cklsmy1k1000sdc103cvn0wwx")
    sf.soundflow.runCommand({
    commandId: 'user:clpsyip7j00037610mkw3xvyq:ckag6jkbd0004wk10x76a5zcn',
    props: {}
    });
    sf.ui.app("com.apple.systempreferences").mainWindow.tabGroups.first.scrollAreas.first.tables.whoseDescription.is("sound output devices").first.children.whoseRole.is("AXRow").allItems[1].textFields.whoseValue.is("Carbon | Expanded:Core Audio Primary").first

    Solved in post #5, click to view
    • 5 replies
    1. I would use a Terminal utility for this, since the System Prefs window is not very scriptable.

      • Start by installing Homebrew from https://brew.sh/
      • Open up Terminal, install the SwitchAudio-OSX utility by running this: brew install switchaudio-osx
      • You can now run the following in Terminal to get a list of available audio outputs: SwitchAudioSource -a
      • And run this to switch to a device: SwitchAudioSource -s "Device Name"

      Once that's installed, you can then call it from SoundFlow like so:

      sf.system.exec({ commandLine: `SwitchAudioSource -s "Device Name"` });
      
      1. Nathan Salefski @nathansalefski
          2023-12-07 00:10:29.563Z

          Hey Christian,

          The SwitchAudio-OSX utility seems to be working perfectly fine when run in Terminal, but trying to do so from SoundFlow doesn't work. Any ideas as to why that could be?

          1. You may need to specify the full path to the executable.

            Type which SwitchAudioSource in Terminal to get its full path, then in SF replace the commandLine SwitchAudioSource with the full path.

            1. Nathan Salefski @nathansalefski
                2023-12-07 01:10:14.732Z

                That did the trick!

                sf.system.exec({ commandLine: `/opt/homebrew/bin/SwitchAudioSource -s "Device Name"` });
                
                Reply2 LikesSolution
          2. D
            In reply toDanIsrael:
            Dan Israel @DanIsrael
              2023-12-08 16:49:38.152Z

              Thank you both. That works great!