用 osascript 在终端精确设置音量
AppleScript 的 set volume 命令可以把输出音量设为 0–100 的任意数值,非常适合写进脚本。
运行 `osascript -e 'set volume output volume 40'` 可把扬声器音量设为 40%。
01命令
命令
$ osascript -e 'set volume output volume 40'02作用说明
与只能开/关的静音不同,output volume 接受 0 到 100 的任意整数,脚本可以恢复到精确的音量档位。用 `osascript -e 'output volume of (get volume settings)'` 可以读取当前音量,适合在录屏或演示前保存并在结束后恢复。同一条语句里加 `set volume without output muted` 还能顺带取消静音。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- osascript — execute AppleScript (macOS man page)依据: osascript runs AppleScript from the shell; `set volume output volume N` accepts 0-100.
最后验证: 2026-09-17 · 分类: 媒体