使用软件
- karabiner-elements ,官网链接
- switchaudiosource,github.com/deweller
核心是SwitchAudioSource切换audio输出设备
安装过程
switchaudiosource,需要用终端安装,没有brew到https://brew.sh/安装。
brew install switchaudiosource-osx
SwitchAudioSource使用方法
switchaudiosource -a #查看所有音频设备
switchaudiosource -s ‘devname’ #切换到特定音频设备
我的设备举例,在终端使用下面命令
%switchaudiosource -s 'MacBook Air扬声器'
>output audio device set to "MacBook Air扬声器"
#待会要在karabiner-elements中使用,需要知道switchaudiosource的软件路径,可以使用如下
%where switchaudiosource
>/opt/homebrew/bin/switchaudiosource #这是我要知道的路径
到这儿,你已经可以用终端输入特定命令切换音频输出设备;就是命令太长,不方便,所以接着看下面设置。
使用karabiner-elements
这个软件作用是用键盘特定按键或者组合按键,触发其他按键或者组合按键,还能启动app或者向shell发送命令。举例可以:
- 通过它改变a键为b键
- 按shift+a改变为shift+command+option+a,起到简化的作用
据说使用vim编程的喜欢使用,我只是买了日本的macbook键盘极为怪异,用来修改按键😂
安装过程
karabiner-elements,官网链接下载安装,或者用brew安装
brew install karabiner-elements
编写karabinet-elements的json代码
{
"title": "switch audio dev",
"rules": [
{
"description": "switch audio to dev1",
"manipulators": [
{
"from": {
"key_code": "a",
"modifiers": {
"mandatory": ["shift","command"],
"optional": ["control", "option"]
}
},
"to": [
{
"shell_command": "/opt/homebrew/bin/switchaudiosource -s 'MacBook Air扬声器'"
}
],
"type": "basic"
}
]
}
]
}
上述代码保存为chang_audiodev.json,放到~/.config/karabiner/assets/complex_modifications
点击karabiner的图标,settings
在complex modifications中选择add predefined rule
选择这个enable
有如下显示就OK了
按键command+shift+a,就会切换到你要设置音频设备。