是,可通过 applescript 读取 output muted of (get volume settings) 获取 macos 当前静音状态,返回布尔值;也可同时获取音量值,注意静音时音量值未必为 0。
可以通过 applescript 检测 macos 当前是否处于静音状态,核心是读取系统音频输出的静音属性。macos 提供了 system volume 的 applescript 可访问属性,其中 output muted 直接反映当前静音开关状态。
基础检测脚本(返回布尔值)
以下脚本直接返回 true 或 false,表示当前是否静音:
set isMuted to (output muted of (get volume settings))
可封装为可复用函数:
on isSystemMuted()
return output muted of (get volume settings)
end isSystemMuted
<p>-- 使用示例:
-- if isSystemMuted() then display alert "系统已静音" </p>同时获取静音状态与音量值
实际应用中常需兼顾静音和音量(如判断“虽未静音但音量为 0”),可一并读取:
set volSettings to get volume settings set isMuted to output muted of volSettings set soundVolume to output volume of volSettings <p>-- 注意:soundVolume 范围是 0–100;静音时该值仍可能非零(例如静音前音量是 50) -- 所以判断“无声”应优先看 isMuted,而非仅看 soundVolume = 0</p>
在 Shell 中调用 AppleScript 检测
适合集成到终端脚本或自动化流程中:
osascript -e 'if (output muted of (get volume settings)) then return "muted" else return "not muted"'
返回字符串便于 Shell 判断:
if [[ $(osascript -e 'output muted of (get volume settings)') == "true" ]]; then
echo "静音中"
else
echo "声音开启"
fi注意事项与边界情况
- 无需管理员权限,普通用户可直接运行
- 该检测反映的是「系统级输出静音」,不区分内置扬声器/蓝牙耳机等设备,由当前默认输出设备决定
- 某些第三方音频工具(如 SoundSource、Boom)可能绕过系统音量控制,此时该脚本仍读取 macOS 原生静音状态,与其界面状态可能不一致
- macOS Ventura 及更新版本中行为一致,兼容性良好











