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 "com.apple.preference.sound" 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.