AppleScriptでSoundの出力先を変えるまで
普段はPCにUSB DACを繋げて音楽を聴いています.しかしSkypeなどをする際にはマイク付きのイヤホンに変えることが多々あります.その時USB DACが間にあるとマイクが使えないのでMacのジャックに差す必要があります.そうすると音の出力先をいちいち設定から開かなければならないため非常に効率が悪いです.そこでAppleScriptで簡単にしてみました.
コード
tell application "System Preferences" quit delay 2 reveal anchor "output" of pane id "com.apple.preference.sound" activate tell application "System Events" tell process "System Preferences" tell tab group 1 of window "サウンド" if (selected of row 1 of table 1 of scroll area 1) then set selected of row 3 of table 1 of scroll area 1 to true --出力が1番目だったら3番目に変える else set selected of row 1 of table 1 of scroll area 1 to true --出力が3番目だったら1番目に変える end if end tell end tell end tell quit end tell
設定
自分の環境では下のようになっているので上のコードで1番目と3番目を入れ替えるようにしました.
ここは自分の設定でコードを書き換えてください.