Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

AppleScript to change Sound preferences Apps
This hint updates this hint which provides an AppleScript that changes the sound input or sound output device selection.

I use Control Plane to manage various preference differences among the different locations (work, home, travel) where I use my MacBook. Control Plane uses various criteria (e.g., IP address, WiFi network name, etc.) to determine your location. Control Plane offers a lot of built in capability to change settings on your Mac based on arriving or leaving a location, and I recommend it highly if you regularly move your Mac among different working environments.

One capability that is not available in Control Plane is the ability to change Sound preferences when you move your Mac from one place to another. In my case, I have a Thunderbolt Display at work, which has built-in speakers and a built-in microphone. At home, I use my MacBook without a second display. I wanted to be able to change the Sound preferences back and forth using Control Plane.

Control Plane does offer the capability, however, to run any application when it detects that have arrived at or have left a particular location. So, you can run any AppleScript.

Relying on the hint comments here, I have updated the scripts in that hint to address my desire for changing sound preferences. My updated script should work on Lion and Mountain Lion. I cannot say whether it will work on earlier versions of OS X.

tell application "System Preferences" to activate
tell application "System Preferences"
	reveal anchor "input" of pane id ""
end tell
tell application "System Events" to tell process "System Preferences"
	tell table 1 of scroll area 1 of tab group 1 of window 1
		select (row 1 where value of text field 1 is "Internal microphone")
	end tell
end tell
quit application "System Preferences"

Note that this script hard codes the name of the Sound preferences pane tab to select and the sound input device to select. To set an output device, you would change "input" to "output" in the 3rd line of the script and then change the device name in the 7th line. I created separate scripts for sound input and sound output for each location where I work. I then simply created a Control Plane rule for each location for sound input and sound output separately.

  • Currently 2.33 / 5
  You rated: 1 / 5 (9 votes cast)

AppleScript to change Sound preferences | 2 comments | Create New Account
Click here to return to the 'AppleScript to change Sound preferences' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript to change Sound preferences
Authored by: deef on Mar 01, '13 09:39:34AM

I two similar scripts to adjust volume and balance when wearing headphones (in part to compensate for partial hearing loss in my R ear):

(sorry about loss of formatting)
#1 Headphones:

set volume 1.5
tell application "System Preferences"
set current pane to pane ""
reveal (first anchor of current pane whose name is "output")
end tell
tell application "System Events"
tell process "System Preferences" to tell slider 1 of group 1 of tab group 1 of window 1 to set value to 0.7
end tell
quit application "System Preferences"

#2 Speakers - edit as follows:
- change the "set volume" line to desired value
- change the "tell process" value to 0 [i.e. center the balance]

[ Reply to This | # ]
AppleScript to change Sound preferences
Authored by: wgscott on Mar 02, '13 03:20:16AM
Thanks for posting this. I found a command-line utility for this that would allow avoiding fragile guy-scripting: SwitchAudio Works for both input and output audio devices.

[ Reply to This | # ]