入出力デバイスを指定のものにする

システム環境設定で、入出力デバイスを指定のものにするスクリプトです。
macOS Big Sur 11.2.3、iMac (Retina 5K, 27-inch, 2019) で動作を確認してます。
selectADevice("output", "SERIES 208i") --出力デバイスを切り替え
selectADevice("input", "SERIES 208i") --入力デバイスを切り替え


on selectADevice(anAnchor, aDviceName)
tell application "System Preferences"
launch
reveal anchor anAnchor of pane id "com.apple.preference.sound"
delay 0.5
end tell
tell application "System Events"
launch
tell process "System Preferences"
tell window "サウンド"
set theTable to table 1 of scroll area 1 of tab group 1
set allDevices to get value of text field 1 of rows of theTable
repeat with i from 1 to (count allDevices)
if (get value of text field 1 of row i of theTable) is aDviceName then
select row i of theTable
exit repeat
end if
end repeat
end tell
end tell
end tell
delay 1
end selectADevice

更新履歴

inserted by FC2 system