美文网首页
Mac设置快捷键切换音频输入设备

Mac设置快捷键切换音频输入设备

作者: passerbyli | 来源:发表于2016-04-21 19:49 被阅读1728次

    mac的输入设备切换确实很麻烦,之前是从来没想过该怎么简化这样的操作。自从看了王自如视频后发现mac自带的脚步程序就可以轻松搞定的事情。自己就没拐过那个弯来怎么没想到(那个视频已经出来了很久很久了)。
    决定自己也来弄一个试一下,自己不会AppleScript,还好有好心网友分享了这段代码。

    tell application "System Preferences"
        activate
        set current pane to pane "com.apple.preference.sound"
    end tell
    tell application "System Events"
        tell application process "系统偏好设置"
            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内置扬声器"
                end if
            end tell
        end tell
    end tell
    

    我的电脑有三个输出设备,电脑自身,显示器自带音响和外接音响。如果你只有两个设备就去掉
    这三行代码

    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前插入

    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 "自定义设备名称"
    

    注意:第二行的row 3 就需要+1改为4了,再添加设备类推。

    代码中的系统偏好设置,声音,输出,如果你的电脑默认语言是中文就不需要修改了。如果默认语言是英语,那就要修改对应标题System Preferences,Sound,Output

    代码有了,怎么使用呢。

    方式一、 直接运行脚本。

    打开脚本编辑器,新建一个脚本。把上面的代码复制到编辑器里保存。点击如下图三角形按钮就运行了。

    Paste_Image.png

    点一次切换一次。无法设置快捷键。

    方式二、通过Alfred来设置快捷键。

    1. 添加一个wolkflows。点击下图加号
    Paste_Image.png
    1. 选择如下图选项System command from hotkey
    Paste_Image.png

    出现下图界面:

    Paste_Image.png
    双击Hotkey,在弹出的窗口Hotkey设置快捷键,这里我设置的是command+f12 9058088F-6DF4-462D-A82C-A8216BCC857F.png
    1. 删除System Command,(右键选择删除)。
      点击右上角的加号选择如下图所示选项:
    3F7155D3-0169-44E1-A057-D17529DC044B.png

    进入下一个界面:

    Paste_Image.png

    Language选择/usr/bin/osascript(AS)。Script复制上面的脚本代码保存。

    1. 最后把两个图标连接上就大功告成。

    按一下command+f12试一下。
    附上ToggleAudio.alfredworkflow

    方式三、通过Keyboard Maestro来设置

    可以通过专业的设置快捷键的软件来实现。比如Keyboard Maestro(键盘大师)来实现此功能就非常简单了。

    Paste_Image.png

    当然也有像AudioSwitcher这样的软件可以实现此功能。

    相关文章

      网友评论

          本文标题:Mac设置快捷键切换音频输入设备

          本文链接:https://www.haomeiwen.com/subject/kaitrttx.html