@
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