Setting Sound Balance with AppleScript


One of the speakers that I use with my computer is a bit temperamental, so I want to make an applescript to quickly adjust my balance from middle, to left, to right, and back to middle automatically, to see if it’s packed in again. However, i can’t seem to find any way of doing it easily, and wondered if anyone could help!

It seems that there’s no easy setting to change to alter the balance (that I could find) - the only solutions I could see seem to use the Applescript UI scripting, which I can’t seem to work out how to use.

Can anyone help me?

Model: Powerbook G4
AppleScript: 1.10.7
Browser: Safari 525.13
Operating System: Mac OS X (10.4)


something like this

tell application "System Preferences"
	reveal anchor "output" of pane id ""
end tell
tell application "System Events"
	tell slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences"
		set value to 1.0
		delay 1
		set value to -1.0
		delay 1
		set value to 0
	end tell
end tell

That’s brilliant, thankyou! Just what I was looking for!

And I was so close, it was just the “set value to…” command that I couldn’t figure out for myself…


I have tried the above mentioned script and in Lion at least the slider’s range is different.
It is not from -1 to 1 but from 0 to 1, with

0 = only left output
0.5 = centered output
1 = only right output

Hope this helps.

I am trying to use your script but with a different configuration! I need a script that change my audio balance to the right automatically when I plug my headphones and when I unplug it backs to “centrum”. it is possible?


You may not need a script for that. On my machine at least, there are separate settings for headphone and speaker output, although only the currently active one is shown in System Preferences.

Open the Sound pane in System Preferences and click the Output button. If your headphones are plugged in, you should see the settings for them. If not, you should see the settings for the speakers. Set the balance as appropriate, unplug (or plug in) the headphones, wait for the display to change, and set the balance again. You should now have separate balances for headphones and speakers. I haven’t tested to see if they survive a restart, but I’ve no reason to suppose that they won’t.