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

2022 年 11 月 22 日
 fl2d

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

3366 次点击
所在节点    Apple
16 条回复
zhaoxin
2022 年 11 月 22 日
你可以尝试写 shortcuts 或者 applescript ,然后绑定快捷键。不过其实这个意义也不大。你把音量图标拖到定栏用鼠标点不是一样吗?
hackpro
2022 年 11 月 22 日
Alfred workflow
fl2d
2022 年 11 月 22 日
@zhaoxin 有特殊需求,需要频繁在耳际与音响之间切换🤦 手点太麻烦
jheroy
2022 年 11 月 22 日
jheroy
2022 年 11 月 22 日
如果不想用 Alfred, 也可以吧上面那个 worklfow 中间的脚本复制过来配合 skhd 直接用快捷键直接那个脚本就切换了, 参数直接写上你的输出设备就行.
jheroy
2022 年 11 月 22 日
直接那个脚本 = 执行那个脚本
fl2d
2022 年 11 月 22 日
@zhaoxin @hackpro @jheroy
我用下面这个命令行工具,配合 karabiner 实现了。
https://github.com/deweller/switchaudio-osx
arac
2022 年 11 月 22 日
也有这个需求,raycast 的官方 repo 找的 swift 脚本改的,配上 alias 也挺好用的
dufu1991
2022 年 11 月 23 日
@fl2d 装好了 switchaudio-osx ,在终端直接运行没问题,但是我尝试通过『自动操作』将 SwitchAudioSource -n 这个命令配置一个全局的快捷键,发现『自动操作』里面执行 shell 命令的时候找不到 SwitchAudioSource 这个命令,奇怪。导致快捷键这个最核心的步骤过不去,你们是如何解决的?
fl2d
2022 年 11 月 23 日
@dufu1991
加路径,/usr/local/bin/SwitchAudioSource
dufu1991
2022 年 11 月 23 日
@fl2d 命令不是很熟,能否详细点。我试了 cd /usr/local/bin/,然后 SwitchAudioSource -n 。还是不行。
fl2d
2022 年 11 月 24 日
@dufu1991
在你的脚本里,命令的前面,加上路径 /usr/local/bin/SwitchAudioSource -n xxx

这个是我这里的路径,你可以用 which SwitchAudioSource 看一下你电脑里的路径
19cm
1 月 25 日
老哥你实现了吗,lua 脚本我倒是实现了,但快捷指令没搞定



-- Hammerspoon: 切换音频输出设备( Headsets <-> Yamaha YVC-330 )
-- 将本文件保存为 ~/.hammerspoon/init.lua ,Reload Config 后按 F12 切换

-- 定义要切换的两个设备
local DEVICES = {
{name = "Headsets", icon = "🎧"}, -- 耳机
{name = "Yamaha YVC-330", icon = "🔈"} -- 雅马哈设备
}

-- 获取所有音频设备
local function getAllAudioDevices()
local devices = {}
for _, dev in ipairs(hs.audiodevice.allOutputDevices()) do
devices[dev:name()] = dev
end
return devices
end

-- 切换音频设备
local function toggleAudioOutput()
local allDevices = getAllAudioDevices()

-- 检查两个设备是否都存在
local device1 = allDevices[DEVICES[1].name]
local device2 = allDevices[DEVICES[2].name]

if not device1 or not device2 then
hs.alert.show("❌ 找不到音频设备")
return
end

-- 获取当前设备
local current = hs.audiodevice.defaultOutputDevice()

-- 决定切换到哪个设备
local target = nil
local targetIcon = ""

if current and current:name() == DEVICES[1].name then
target = device2
targetIcon = DEVICES[2].icon
else
target = device1
targetIcon = DEVICES[1].icon
end

-- 执行切换
if target:setDefaultOutputDevice() then
hs.alert.show(targetIcon .. " 已切换至: " .. target:name())
else
hs.alert.show("❌ 切换失败")
end
end




-- hs.hotkey.bind({"ctrl"}, "f1", toggleAudioOutput)

-- 绑定热键 F12 (没有修饰键)
hs.hotkey.bind({}, "f13", toggleAudioOutput)

-- 加载提示
print("🎧 音频切换脚本已加载")
print("📢 按 F12 切换设备:")
for i, device in ipairs(DEVICES) do
print(" " .. i .. ". " .. device.icon .. " " .. device.name)
end
hanguokai
14 小时 12 分钟前
@19cm 我前几天自己做了一个快捷键切换音频设备的 App ,简单易用 https://apps.apple.com/app/hotkey-audio-switcher/id6802059852
19cm
10 小时 47 分钟前
@hanguokai 链接有问题 直接发下 app 名字吧
hanguokai
1 小时 11 分钟前
@19cm App Store 上搜索 Hotkey Audio Switcher 。那个链接在电脑浏览器上打开没问题。

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

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

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

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

© 2021 V2EX