比如用键盘快捷键切换 内置音箱 /耳机 /蓝牙音箱。
比如用键盘快捷键切换 内置音箱 /耳机 /蓝牙音箱。
1
zhaoxin Nov 22, 2022
你可以尝试写 shortcuts 或者 applescript ,然后绑定快捷键。不过其实这个意义也不大。你把音量图标拖到定栏用鼠标点不是一样吗?
|
2
hackpro Nov 22, 2022 via iPhone
Alfred workflow
|
4
jheroy Nov 22, 2022
|
5
jheroy Nov 22, 2022
如果不想用 Alfred, 也可以吧上面那个 worklfow 中间的脚本复制过来配合 skhd 直接用快捷键直接那个脚本就切换了, 参数直接写上你的输出设备就行.
|
6
jheroy Nov 22, 2022
直接那个脚本 = 执行那个脚本
|
7
fl2d OP |
8
arac Nov 22, 2022
也有这个需求,raycast 的官方 repo 找的 swift 脚本改的,配上 alias 也挺好用的
|
9
dufu1991 Nov 23, 2022
@fl2d 装好了 switchaudio-osx ,在终端直接运行没问题,但是我尝试通过『自动操作』将 SwitchAudioSource -n 这个命令配置一个全局的快捷键,发现『自动操作』里面执行 shell 命令的时候找不到 SwitchAudioSource 这个命令,奇怪。导致快捷键这个最核心的步骤过不去,你们是如何解决的?
|
12
fl2d OP @dufu1991
在你的脚本里,命令的前面,加上路径 /usr/local/bin/SwitchAudioSource -n xxx 这个是我这里的路径,你可以用 which SwitchAudioSource 看一下你电脑里的路径 |
13
19cm Jan 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 |
14
hanguokai 1 day ago
@19cm 我前几天自己做了一个快捷键切换音频设备的 App ,简单易用 https://apps.apple.com/app/hotkey-audio-switcher/id6802059852
|
21
19cm 7h 11m ago
@hanguokai #20 所以要有排除设备的名单啊,比如 5 个设备,排除掉三个, 剩下的不就是在两个来回切了,f 区切是最方便点的,另外还要有记忆功能最好, 比如笔记本在家里 是哪几个设备,在公司又是哪几个设备
|
22
hanguokai 6h 58m ago
@19cm 通用软件要考虑所有人的情况,不能假设所有人都只有 2 个输出设备(或者是通过排除选项达成仅剩 2 个)。设置选项是有记忆的,无论是家里还是公司排除的设备都是记住的。
|
27
hanguokai 4h 15m ago
@19cm 类似操作系统 cmd+tab 这种功能单键是实现不了的,所以不允许单键。不松开 cmd 时再次按下 tab 键可以连续切换到下一个,一旦松开 cmd 键就取消悬浮窗口并执行切换。这里至少靠 2 个键才实现的。
|
28
19cm 3h 21m ago
@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 |