macOS 下,能用快捷键切换音频输出设备么?

2022 年 11 月 22 日
 fitbit

比如用键盘快捷键切换 内置音箱 /耳机 /蓝牙音箱。

3723 次点击
所在节点    Apple
29 条回复
19cm
8 月 26 日
@hanguokai #20 所以要有排除设备的名单啊,比如 5 个设备,排除掉三个, 剩下的不就是在两个来回切了,f 区切是最方便点的,另外还要有记忆功能最好, 比如笔记本在家里 是哪几个设备,在公司又是哪几个设备
hanguokai
8 月 26 日
@19cm 通用软件要考虑所有人的情况,不能假设所有人都只有 2 个输出设备(或者是通过排除选项达成仅剩 2 个)。设置选项是有记忆的,无论是家里还是公司排除的设备都是记住的。
19cm
8 月 26 日
@hanguokai #22 这不是很简单吗,你多个设置选项不就行行了, 一个快捷键顺序切换, 一个按你原来的
hanguokai
8 月 26 日
@19cm 可以是可以,但是现有的快捷键功能也是按一下就切换到下一个设备。区别仅仅是组合快捷键和单键的区别。
19cm
8 月 26 日
@hanguokai #24 所以你放开单键就行了啊
19cm
8 月 26 日
@hanguokai #24 另外可以多加两个可配置快捷键项, 或者可以客户无限自己定义加,比如一个键快速 1 号二级,一个键切 3 号音响
这样灵活性高很多
hanguokai
8 月 26 日
@19cm 类似操作系统 cmd+tab 这种功能单键是实现不了的,所以不允许单键。不松开 cmd 时再次按下 tab 键可以连续切换到下一个,一旦松开 cmd 键就取消悬浮窗口并执行切换。这里至少靠 2 个键才实现的。
19cm
8 月 26 日
@hanguokai #27 为啥要类似 cmd+tab, 我自己写脚本都实现了单键切换
-- 二进制路径
set bin to "/opt/homebrew/bin/SwitchAudioSource"

-- 设备定义
set device1 to "EarPods"
set icon1 to "🎧"

set device2 to "Yamaha YVC-330"
set icon2 to "🔈"

-- 获取当前设备 & 所有设备
set currentDevice to do shell script bin & " -c -t output"
set allDevices to do shell script bin & " -a -t output"

-- 判断存在性
set hasDevice1 to allDevices contains device1
set hasDevice2 to allDevices contains device2

-- ❌ 两个都不存在
if (not hasDevice1) and (not hasDevice2) then
display notification icon1 & " " & device1 & " 未连接 / " & icon2 & " " & device2 & " 未连接,暂不切换"
return
end if

-- ⚠️ 只存在 device1 ( device2 未连接)
if hasDevice1 and (not hasDevice2) then
do shell script bin & " -s " & quoted form of device1
display notification icon2 & device2 & " 未连接,已切换至" & icon1 & " " & device1
return
end if

-- ⚠️ 只存在 device2 ( device1 未连接)
if hasDevice2 and (not hasDevice1) then
do shell script bin & " -s " & quoted form of device2
display notification icon1 & " " & device1 & " 未连接,已切换至" & icon2 & " " & device2
return
end if

-- ✅ 两个都存在 → 正常切换
if currentDevice contains device1 then
do shell script bin & " -s " & quoted form of device2
display notification "已切换至: " & icon2 & device2
else
do shell script bin & " -s " & quoted form of device1
display notification "已切换至: " & icon1 & " " & device1
end if
hanguokai
8 月 26 日
@19cm 前面解释了,因为用户可能需要在多个设备之间切换。以 cmd+tab 为例,它是一个快捷键,但它实现了 2 个动作:选择和确认切换。如果只有 2 个固定的设备,不需要选择,只切换就可以了,是可以单键完成的。我当前的产品是要满足用户有大于等于 2 个设备使用的。

当然技术层面上,提供两套快捷键完成不同逻辑的功能也可以。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/897085

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX