mac的輸入設(shè)備切換確實很麻煩,之前是從來沒想過該怎么簡化這樣的操作。自從看了王自如視頻后發(fā)現(xiàn)mac自帶的腳步程序就可以輕松搞定的事情。自己就沒拐過那個彎來怎么沒想到(那個視頻已經(jīng)出來了很久很久了)。
決定自己也來弄一個試一下,自己不會AppleScript,還好有好心網(wǎng)友分享了這段代碼。
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "系統(tǒng)偏好設(shè)置"
tell tab group 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
set deviceselected to "外置音響"
else if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 3 of table 1 of scroll area 1 to true
set deviceselected to "LG顯示器"
else
set selected of row 1 of table 1 of scroll area 1 to true
set deviceselected to "MAC內(nèi)置揚聲器"
end if
end tell
end tell
end tell
我的電腦有三個輸出設(shè)備,電腦自身,顯示器自帶音響和外接音響。如果你只有兩個設(shè)備就去掉
這三行代碼
else if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 3 of table 1 of scroll area 1 to true
set deviceselected to "LG顯示器"
如果你的輸出設(shè)備不止這三個就在else前插入
else if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 3 of table 1 of scroll area 1 to true
set deviceselected to "自定義設(shè)備名稱"
注意:第二行的row 3 就需要+1改為4了,再添加設(shè)備類推。
代碼中的系統(tǒng)偏好設(shè)置,聲音,輸出,如果你的電腦默認語言是中文就不需要修改了。如果默認語言是英語,那就要修改對應(yīng)標題System Preferences,Sound,Output。
代碼有了,怎么使用呢。
方式一、 直接運行腳本。
打開腳本編輯器,新建一個腳本。把上面的代碼復制到編輯器里保存。點擊如下圖三角形按鈕就運行了。

Paste_Image.png
點一次切換一次。無法設(shè)置快捷鍵。
方式二、通過Alfred來設(shè)置快捷鍵。
- 添加一個wolkflows。點擊下圖加號

Paste_Image.png
- 選擇如下圖選項
System command from hotkey:

Paste_Image.png
出現(xiàn)下圖界面:

Paste_Image.png
雙擊
Hotkey,在彈出的窗口Hotkey設(shè)置快捷鍵,這里我設(shè)置的是command+f12。

9058088F-6DF4-462D-A82C-A8216BCC857F.png
- 刪除
System Command,(右鍵選擇刪除)。
點擊右上角的加號選擇如下圖所示選項:

3F7155D3-0169-44E1-A057-D17529DC044B.png
進入下一個界面:

Paste_Image.png
Language選擇/usr/bin/osascript(AS)。Script復制上面的腳本代碼保存。
- 最后把兩個圖標連接上就大功告成。
按一下command+f12試一下。
附上ToggleAudio.alfredworkflow。
方式三、通過Keyboard Maestro來設(shè)置
可以通過專業(yè)的設(shè)置快捷鍵的軟件來實現(xiàn)。比如Keyboard Maestro(鍵盤大師)來實現(xiàn)此功能就非常簡單了。

Paste_Image.png
當然也有像AudioSwitcher這樣的軟件可以實現(xiàn)此功能。