Macのサウンド出力先を切り替えるAppleScript
iMac用にHDMI出力コネクタを買ったのだが、音声の出力先をHDMI(外部ディスプレイ)と内蔵スピーカで切り替えたいことが良くあるので、AppleScriptにしてみた。
システム環境設定をUI操作しているので、「ユニバーサルアクセス>補助装置にアクセスできるようにする」にチェックする必要あり。AppleScriptのスクリプトメニューに登録しておくと便利かも。
環境によって、row番号やラベル文字列が違うかもしれないので、適当に修正して。
tell application "System Preferences" activate set current pane to pane id "com.apple.preference.sound" end tell tell application "System Events" tell process "System Preferences" tell tab group 1 of window "サウンド" click radio button "出力" if (selected of row 1 of table 1 of scroll area 1) then set selected of row 2 of table 1 of scroll area 1 to true else set selected of row 1 of table 1 of scroll area 1 to true end if end tell end tell end tell quit application "System Preferences"
参考:http://www.oreillynet.com/mac/blog/2006/07/applescript_audio_output_switc.html