AppleScript实现macOS定时静音提醒有两种方案:一是通过日历事件触发打包的应用程序,自动静音并弹窗;二是用launchd配置plist文件,按指定时间(如每晚22:00)执行静音脚本并通知。
用 applescript 实现 macos 定时静音提醒,核心是结合系统日历事件或定时触发机制,在指定时间自动执行静音操作并弹出提醒。macos 本身不支持直接“定时运行 applescript”,需借助“日历”app 的提醒功能或“launchd”后台任务来触发脚本。下面提供两种稳定、易用的方案:
方案一:用「日历」+「提醒」触发 AppleScript(推荐新手)
这是最简单可靠的方式——把 AppleScript 打包为应用,再让 macOS 日历在指定时间打开它,自动执行静音 + 提示。
- 新建 AppleScript(例如:静音并弹窗提醒):
set volume output muted true
display alert "⏰ 已静音!请专注当前任务" message "系统音量已关闭,避免干扰" as critical buttons {"好的"} default button "好的"
- 在 Script Editor 中保存为「应用程序」(格式选「应用程序」,勾选“运行前显示此脚本” → 取消勾选,确保静默运行)
- 打开「日历」App,新建一个日历(如叫“静音提醒”),添加一个事件,设置时间为你要触发的时间
- 在事件详情中,点击「提醒」→「添加提醒」→「打开文件」→ 选择你刚保存的 .app 应用
- 保存后,到点 macOS 会自动运行该应用:静音 + 弹出警示窗口
方案二:用 launchd 后台服务定时执行(适合固定周期)
若需每天/每小时重复静音(如每晚10点自动静音),可用 launchd 创建 plist 配置,实现精准定时。
使用 inotes CLI 从终端管理 Apple Notes。当需要在 macOS 的 Notes.app 中列出、读取、创建、编辑、删除或搜索备忘录时使用。
- 先写好静音脚本(保存为 ~/Scripts/mute-and-notify.scpt):
set volume output muted true say "已进入静音模式" using "Ting-Ting" delay 0.5 do shell script "osascript -e 'display notification \"? 静音已启用\" with title \"专注提醒\"'"
- 创建 launchd 配置文件(如 ~/Library/LaunchAgents/com.user.mutealert.plist),内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.mutealert</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/你的用户名/Scripts/mute-and-notify.scpt</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>22</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>RunAtLoad</key>
<false/>
</dict>
</plist>
- 替换其中 你的用户名,然后加载服务:
launchctl load ~/Library/LaunchAgents/com.user.mutealert.plist - 验证是否生效:
launchctl list | grep mutealert;可手动触发测试:launchctl start com.user.mutealert
小技巧与注意事项
- 静音命令
set volume output muted true是即时生效的,无需管理员权限 - 若想恢复音量,可另写一个「取消静音」脚本:
set volume output muted false - 通知样式支持
display notification(轻量)或display alert(强制交互),按需选择 - launchd 方案中,
StartCalendarInterval支持更复杂规则(如每周一至五),详见 Apple 官方文档 - 脚本路径必须为绝对路径,且 launchd 运行环境无 GUI 上下文,因此不能用
display dialog(会失败),请改用display notification或say
扩展思路:根据场景智能静音
可进一步增强逻辑,比如检测当前应用、时间区间或屏幕状态:
- 只在使用「Notes」「Typora」等写作 App 时静音:
if (name of first application process whose frontmost is true) is in {"Notes", "Typora", "Ulysses"} then … - 结合「快捷指令」自动化:用 Shortcuts 创建「静音提醒」快捷指令,再通过 AppleScript 调用:
do shell script "shortcuts run '静音提醒'" - 配合「聚焦搜索」快速唤醒:将脚本保存为快速操作(Quick Action),分配键盘快捷键(如 ⌘⌥M)

















