Hello all,
I have an AppleScript that sets the Input, Output and Sound Effects in System Preferences.
It runs fine, if System Preferences is already activated.
tell application "System Preferences" to reveal anchor "Input" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
set selected of (row 1 where value of text field 1 is "Yeti Nano") of table 1 of scroll area 1 to true
end tell
end tell
tell application "System Preferences" to reveal anchor "Output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
set selected of (row 1 where value of text field 1 contains "Max") of table 1 of scroll area 1 to true
end tell
end tell
tell application "System Preferences" to reveal anchor "Effects" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
click pop up button 1
click menu item "Selected sound output device" of menu 1 of pop up button 1
end tell
end tell
If I add code to activate System Preferences…
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Preferences" to reveal anchor "Input" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
set selected of (row 1 where value of text field 1 is "Yeti Nano") of table 1 of scroll area 1 to true
end tell
end tell
tell application "System Preferences" to reveal anchor "Output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
set selected of (row 1 where value of text field 1 contains "Max") of table 1 of scroll area 1 to true
end tell
end tell
tell application "System Preferences" to reveal anchor "Effects" of pane id "com.apple.preference.sound"
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
click pop up button 1
click menu item "Selected sound output device" of menu 1 of pop up button 1
end tell
end tell
…I get this error:
System Events got an error: Can’t set window "Sound" of process "System Preferences" to true.
Any ideas on what I mistake(s) I am making?