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


Click here to return to the 'An AppleScript to change sound output device' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to change sound output device
Authored by: RobLewis on Apr 08, '08 10:49:52AM

Just (almost) what I was looking for. I want to toggle between 2 sound outputs with a keystroke. Also, removed an extraneous line and fixed the problem that the "Output" pane must be preselected for the script to work.

property speakers : "Headphones" --ext. speakers are connected to headphone output
property headset : "Logitech USB Headset"

tell application "System Preferences" to activate
tell application "System Events"
get properties
tell process "System Preferences"
click menu item "Sound" of menu "View" of menu bar 1
delay 2
click radio button "Output" of tab group 1 of window "sound"
delay 1
set theRows to every row of table 1 of scroll area 1 of tab group 1 of window "sound"
repeat with aRow in theRows
if selected of aRow then
set curr_output to (value of text field 1 of aRow as text)
if curr_output is speakers then set desired_output to headset
if curr_output is headset then set desired_output to speakers
exit repeat
end if
end repeat
repeat with aRow in theRows
if (value of text field 1 of aRow as text) is desired_output then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
tell application "System Preferences" to quit



[ Reply to This | # ]