I am using the following script, with success, to set the Sound Output to a USB Headset. How do I get it to set Sound Input to the same USB Headset? I have tried to modify it…but, I just don’t know enough about applescripting to get it to work right. Any ideas?
Thanks.
Shayne
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
set theRows to every row of table 1 of scroll area 1 of ¬
tab group 1 of window "sound"
set theOutputs to {} as list
repeat with aRow in theRows
if (value of text field 1 of aRow as text) ¬
is equal to "Plantronics Headset" then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
tell application "System Preferences" to quit
I don’t have inputs to test out, but I can slightly simplify the beginning:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
reveal (first anchor of current pane whose name is "input")
-- You can change "input" to "output" or "effects"
end tell
tell application "System Events"
tell process "System Preferences"
-- switch input
end tell
end tell
quit application "System Preferences"
Thanks Bruce. I see that your start solution is simpler. I’m embarassed to admit that I just don’t know how to knit what you’ve given me, with what I already have. Can you please tell me specifically, which lines from my original solution should be migrated into your suggestion, and where should they go? If you can make it stupid-proof, that’d be great.
Hmm. I think you’re script should work. Try this, and let us know if it works.
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
reveal (first anchor of current pane whose name is "input")
end tell
tell application "System Events"
launch
tell process "System Preferences"
set theRows to every row of table 1 of scroll area 1 of tab group 1 of window 1
repeat with aRow in theRows
if (value of text field 1 of aRow) is equal to "Plantronics Headset" then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
quit application "System Preferences"
The following version sets the sound input and output to whatever you choose. Skype users can use this to quickly change their audio input and output setting to match their Skype preferences setting. A second script could be run to switch it back to your prefered default. A keyboard shortcut would make this even easier (and help avoid the scamble to reset OS sound preferences when a Skype call comes in ;-).
All hail Bruce!
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
reveal (first anchor of current pane whose name is "input")
end tell
tell application "System Events"
launch
tell process "System Preferences"
set theRows to every row of table 1 of scroll area 1 of tab group 1 of window 1
repeat with aRow in theRows
if (value of text field 1 of aRow) is equal to "Plantronics Headset" then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
reveal (first anchor of current pane whose name is "output")
end tell
tell application "System Events"
launch
tell process "System Preferences"
set theRows to every row of table 1 of scroll area 1 of tab group 1 of window 1
repeat with aRow in theRows
if (value of text field 1 of aRow) is equal to "Plantronics Headset" then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
quit application "System Preferences"
I tried all these scripts and the
“set theRows to every row of table 1 of scroll area 1 of tab group 1 of window 1”
Hangs on every try, at ‘every row’ statememnt (I have 3)
Result
“System Events got an error: NSReceiverEvaluationScriptError: 4”
never even gets to the point of evaluating the rows.