No internet connection
  1. Home
  2. Macro and Script Help

Select sound output mac

By Ofer Tiberin @Ofer_Tiberin
    2024-04-12 08:18:53.175Z

    Title

    Select sound output mac

    What do you expect to happen when you run the script/macro?

    Hi, I'm trying to create a macro for selecting audio output for my mac, for some reason picking “sound” in System Settings with “Mouse Click Relative To UI Element” action doesn’t work for me, would love some help!

    Are you seeing an error?

    What happens when you run this script?

    It goes up to opening System Settings but nothing happens after that

    How were you running this script?

    I clicked the "Run Script" or "Run Macro" button in SoundFlow

    How important is this issue to you?

    4

    Details

    {
        "inputExpected": "Hi, I'm trying to create a macro for selecting audio output for my mac, for some reason picking “sound” in System Settings with  “Mouse Click Relative To UI Element” action doesn’t work for me, would love some help!",
        "inputIsError": false,
        "inputWhatHappens": "It goes up to opening System Settings but nothing happens after that",
        "inputHowRun": {
            "key": "-MpfwYA4I6GGlXgvp5j1",
            "title": "I clicked the \"Run Script\" or \"Run Macro\" button in SoundFlow"
        },
        "inputImportance": 4,
        "inputTitle": "Select sound output mac"
    }

    Source

    //Macro converted to script
    
    
    sf.app.launch({
        path: "/System/Applications/System Settings.app",
    });
    
    sf.ui.app("com.apple.systempreferences").mainWindow.groups.first.splitGroups.first.groups.first.scrollAreas.first.children.whoseRole.is("AXOutline").whoseDescription.is("Sidebar").first.children.whoseRole.is("AXRow").allItems[11].children.whoseRole.is("AXCell").first.children.whoseRole.is("AXStaticText").whoseValue.is("Sound").first.mouseClickElement();
    
    sf.ui.app("com.apple.systempreferences").mainWindow.groups.first.splitGroups.first.groups.allItems[1].groups.first.scrollAreas.first.groups.allItems[1].scrollAreas.first.children.whoseRole.is("AXOutline").first.children.whoseRole.is("AXRow").first.children.whoseRole.is("AXCell").first.groups.first.children.whoseRole.is("AXStaticText").whoseValue.is("MacBook Pro Speakers").first.mouseClickElement();
    
    
    

    Links

    User UID: V2dqPdWQXYOIhkPbVifwSiA7icx1

    Feedback Key: sffeedback:V2dqPdWQXYOIhkPbVifwSiA7icx1:-NvGNpaCDkNHO_4R588K

    Feedback ZIP: YE/S8acxhleN0uZsacs7pi9izhke7DIl8lp/Cynt2kkRkeLGPnLuHlR3OY5ZGMV11iybquBtj6xaYgYt/dEzrh5SxTiNdDUlH2IwdMsK1f/GNHhdoxCToSFmX2Vecg8z2brAtJU4M/BGGhiAxQjRVYPeWbhWaPcM124V9g988+q2isWW97gasYqP1pDf3ylpDAVUFVybpVqh7g/eQTkacbnMVneta/Os4es1ZxTn1M9m7vbB1tuextHrB5zjFqkgDk+ieUK2GQ9Fe6pU78jenwBFUb7fI9za5L9jhHlomkdMLDEAAjpX6JUUodLya/KW0RUL3b8+yXYoc8Wc4/S78w==

    • 2 replies
    1. Chad Wahlbrink @Chad2024-10-29 16:04:12.639Z

      Hi @Ofer_Tiberin,

      At the end of this post, I go over a few ways to set the sound output on a Mac. Let me know if those posts help you out!

      You can get device IDs for your audio devices with this short script:

      log(sf.audio.getAudioDevices().devices)
      

      The device IDs will show up in the log. You can access the full log here:

      The output will look something like this:

      [
      {
              "DeviceId": 126,
              "DeviceName": "Universal Audio Thunderbolt",
              "IsActiveInput": false,
              "IsActiveOutput": false
          }
      ]
      

      Then, you can set an audio device by the device ID with another short script like this:

      sf.audio.selectAudioDevice({deviceId:126})
      
      1. Chad Wahlbrink @Chad2024-10-29 16:16:10.717Z

        Better yet, you could select the sound output by name like this:

        
        let outputName = 'Universal Audio Thunderbolt'
        
        // Get the audio device ID for the named device
        let namedAudioDeviceID = sf.audio.getAudioDevices().devices.filter(x => x.deviceName == outputName)[0].deviceId
        
        // Set output
        sf.audio.selectAudioDevice({deviceId:namedAudioDeviceID})