I Can Get the Sound Balance But Can't Set It (Ventura)

I’m running Ventura 13.3.1. This AppleScript gets the Sound Output Balance but won’t set it. Am I phrasing it wrong?

Thanks for any help.

-- SET SOUND BALANCE

tell application "System Settings"
	activate
	
	-- activate the Output pane
	reveal anchor "output" of pane id "com.apple.Sound-Settings.extension"
	
end tell

-- SET YOUR BALANCE SLIDER TO RIGHT OR LEFT, THEN RUN THIS SCRIPT.

tell application "System Events"
	
	
	tell application process "System Settings"
		
		-- this runs without error but does not set the value:
		set value of value indicator 1 of slider "Balance" of group 3 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Sound" to 0.5
		
		-- this works:
		get value of value indicator 1 of slider "Balance" of group 3 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Sound"
		
	end tell
	
	
end tell

I believe that you will want to speak to the Slider rather than the value indicator. In addition, the value does not appear to be editable. Perhaps this will get corrected in a future update. This will set the slider ‘close’ to a desired value. The increment is chunky. If you’re trying for balanced center result I would suggest first incrementing it to all the way to 1 so that the decrements can land at .5

--Running under AppleScript 2.8, MacOS 13.0.1
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


set targetValue to 0.35

tell application "System Events"
    tell its application process "System Settings"
        tell its window "Sound"
            tell slider "Balance" of group 3 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
                repeat while value < targetValue
                    perform action "AXIncrement"
                end repeat
                repeat while value > targetValue
                    perform action "AXDecrement"
                end repeat
            end tell
        end tell
    end tell
end tell
1 Like

Thank you so much Paul. After some experimentation I found that decrementing from 1.0 got very close to 0.5 (as you said), but incrementing from 0.0 ends up at exactly 0.5. So I changed your script to the one below. And while I’m pretty sure I would not be able to hear the difference, I like knowing that it is set to dead center.

I’m also curious about - perform action “AXDecrement”
I couldn’t find it in any of the AppleScript documentation that I know of. Where is it from? A scripting addition perhaps?

Thanks again!


set targetValue to 0.5

tell application "System Events"
	tell its application process "System Settings"
		tell its window "Sound"
			tell slider "Balance" of group 3 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				repeat while value > 0.0
					perform action "AXDecrement"
				end repeat
				repeat while value < targetValue
					perform action "AXIncrement"
				end repeat
				get value
			end tell
		end tell
	end tell
end tell