El siguiente es un applescript que uso para cambiar los dispositivos de salida de audio:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "System Preferences"
tell tab group 1 of window "Sound"
click radio button "Output"
if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 1 of table 1 of scroll area 1 to true
set deviceselected to "Headphones"
else
set selected of row 2 of table 1 of scroll area 1 to true
set deviceselected to "MX279"
end if
end tell
end tell
end tell
tell application "System Preferences" to quit
Funcionó en Yosemite, pero cuando actualicé a El Capitan me da el siguiente error:
"System Events got an error: Can't get tab group 1 of window \"Sound\" of application process \"System Preferences\". Invalid index"
No estoy muy familiarizado con AppleScript, por lo que cualquier idea de por qué esto podría estar sucediendo será muy apreciada.
En la primera parte de su secuencia de comandos, carga el Sound
panel de preferencias. Puede suceder que el panel no esté completamente cargado antes de enviarle comandos en la segunda parte del script. El error dice que tab group 1
(el que contiene la Output
pestaña) no existe en el momento en que intenta acceder a él.
Para asegurarnos de que tab group 1
existe, podemos esperarlo con estas dos líneas:
repeat until exists tab group 1 of window "Sound"
end repeat
El guión completo:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat until exists tab group 1 of window "Sound"
end repeat
tell tab group 1 of window "Sound"
click radio button "Output"
if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 1 of table 1 of scroll area 1 to true
set deviceselected to "Headphones"
else
set selected of row 2 of table 1 of scroll area 1 to true
set deviceselected to "MX278"
end if
end tell
end tell
end tell
tell application "System Preferences" to quit
gdavtor
Arturo
bmike
zıəs uɐɟəʇs