在 macOS 上,Google Antigravity 完成时获得通知的最简单方式,是在 ~/.gemini/config/hooks.json 中添加一个 Stop hook,运行一个调用 osascript -e 'display notification ...' 的脚本。它适用于你运行 agy 的任何终端,从下一个会话起就会运行,没有信任步骤。请在系统设置中允许“脚本编辑器”发送通知,否则第一条提醒常常会被悄无声息地丢掉。如果想要可点击、能把终端带到前台的提醒,请改用 Homebrew 中的 terminal-notifier。
01Mac 上的 hook 文件
Antigravity 的全局 hook 文件是 ~/.gemini/config/hooks.json,也就是 /Users/you/.gemini/config/hooks.json。agy 命令行、桌面应用和 IDE 都会读取它。项目中也可以有 .agents/hooks.json;两个文件都会加载、都会触发。
顶层键是命名的组。把你的提醒放在单独的组中,比如 my-alerts,这样它们可以与文件中的其他内容(包括 Antigravity Notifier 的 antigravity-notifier 组)并存而互不干扰。
02osascript hook
将下面的内容保存为 ~/.gemini/hooks/done.sh:
#!/bin/sh
# Antigravity Stop hook: a macOS notification with the project folder's name.
input=$(cat)
project=$(printf '%s' "$input" | python3 -c 'import json,os,sys; print(os.path.basename(json.load(sys.stdin).get("cwd","")))' 2>/dev/null)
osascript -e "display notification \"Antigravity has finished\" with title \"Antigravity: $project\" sound name \"Glass\"" >/dev/null 2>&1
exit 0
设为可执行:
chmod +x ~/.gemini/hooks/done.sh
然后把这个组添加到 ~/.gemini/config/hooks.json,路径中使用你自己的主目录:
{
"my-alerts": {
"Stop": [
{ "type": "command", "command": "/Users/you/.gemini/hooks/done.sh", "timeout": 10 }
]
}
}
hook 会在标准输入上收到一个 JSON payload,其中 cwd 是会话所在的文件夹,脚本会把它作为标题,方便你区分不同会话。如果没有安装 python3,macOS 会在第一次运行时提示安装命令行开发者工具;你也可以删掉 project 这一行,使用固定标题。
启动一个新的 agy 会话。已经在运行的会话不会读取改动。
03允许“脚本编辑器”发送通知
osascript 以脚本编辑器的身份显示通知。在新 Mac 上,第一条通知常常会被悄悄丢掉。解决方法:
- 在“终端”中运行
osascript -e 'display notification "test" with title "Antigravity"'。 - 打开系统设置 > 通知,找到脚本编辑器,开启允许通知。如果希望通知一直留在屏幕上直到你关闭,请选择提醒。
- 确认没有专注模式把它隐藏(见下文)。
04用 terminal-notifier 实现可点击的通知
terminal-notifier(brew install terminal-notifier)支持分组,新提醒会替换旧提醒,还支持点击操作,把你的终端带到前台。把 done.sh 中的 osascript 这一行替换为:
/opt/homebrew/bin/terminal-notifier -title "Antigravity: $project" -message 'Antigravity has finished' -group antigravity -activate com.apple.Terminal >/dev/null 2>&1
把 bundle id 换成你的终端:iTerm2 用 com.googlecode.iterm2,Ghostty 用 com.mitchellh.ghostty,VS Code 用 com.microsoft.VSCode。请使用完整路径,因为 hook 看到的 PATH 可能与你的 shell 不同。在 Intel Mac 上,Homebrew 位于 /usr/local/bin。
05当 Antigravity 向你提问时
Antigravity 没有通知或权限事件。问题会以对 ask_question 工具的 PreToolUse 调用形式到达 hook,这就是要发出提醒的时机。问题在于:Antigravity 采用失败即拒绝,所以一个没有输出决定、失败或超时的 PreToolUse hook 会阻止该工具。请始终输出 {"decision":"allow"},把这次调用交给 Antigravity 自己的规则。
保存为 ~/.gemini/hooks/tool.sh 并设为可执行:
#!/bin/sh
# Antigravity PreToolUse hook: alert on questions, then ALWAYS allow.
input=$(cat)
tool=$(printf '%s' "$input" | python3 -c 'import json,sys; print((json.load(sys.stdin).get("toolCall") or {}).get("name",""))' 2>/dev/null)
if [ "$tool" = "ask_question" ]; then
osascript -e 'display notification "Antigravity has a question for you" with title "Antigravity"' >/dev/null 2>&1
fi
echo '{"decision":"allow"}'
exit 0
然后把它添加到你的组中 Stop 的旁边:
"PreToolUse": [
{ "matcher": "*", "hooks": [ { "type": "command", "command": "/Users/you/.gemini/hooks/tool.sh", "timeout": 10 } ] }
]
对每个 run_command 都发提醒是可以的,但会很吵:交互式会话以 Auto 模式启动,沙盒中的“安全”命令无需询问即可运行,而 hook 无法判断哪些命令会停下来等你。
06只要声音
如果你更想听到而不是看到,就在脚本中用下面这行代替通知:
afplay /System/Library/Sounds/Glass.aiff
07专注模式与勿扰模式
专注模式会隐藏不在其允许列表中的应用的通知。如果提醒在专注模式关闭时出现、开启时消失,请打开系统设置 > 专注模式,选择该模式,把脚本编辑器(对应 osascript)或 terminal-notifier 加入允许的应用。如果你希望专注时 Antigravity 保持安静,就不要把它们加进去。
08或者交给 antigravity-notifier
Mac 通知只会留在 Mac 上。要在手机上收到提醒并直接回答,Antigravity Notifier 的免费 antigravity-notifier 工具会替你设置好 hook,适用于 Mac、Windows 和 Linux:
curl -fsSL https://antigravitynotifier.com/install.sh | sh
或者用 Homebrew:brew trust --formula touch-tap/tap/antigravity-notifier && brew install touch-tap/tap/antigravity-notifier。配对只会在 ~/.gemini/config/hooks.json 中添加一个命名组 antigravity-notifier,保留一次性备份,不会动你自己的组。
配对 iPhone 或 Android 应用后,你会收到“Antigravity 已完成”及其最后一条消息,你不在时可以允许或拒绝命令,可以回答 Antigravity 的问题,还有一个输入框用来发送下一条指令。在 Mac 上,屏幕锁定会立即被视为离开;如果屏幕未锁定且你在最近 30 秒内有输入,就不会等待手机。在 iPhone 上,锁屏卡片会显示当前步骤以及改动的文件和行数。它适用于任何终端中的 agy;暂不支持桌面应用和 IDE。
Antigravity Notifier 是独立产品,由 TouchTap Ltd 开发,与 Google 无关联。Google 免费的 Remote Control 是另一种通知到手机的方式,通过手机浏览器使用。应用价格见价格。
09常见问题
Antigravity 自己会显示 macOS 通知吗?
我们还没有验证桌面应用或 IDE 自己会显示什么。在 agy 命令行中,hook 是获得通知的可靠方式。
我的脚本在“终端”中能用,但从 Antigravity 运行就不行,为什么?
先启动一个新会话:改动从下一个会话起生效。然后检查 hooks.json 是有效的 JSON(python3 -m json.tool ~/.gemini/config/hooks.json),command 中的路径是绝对路径,并且脚本可执行。
为什么添加 hook 后我的命令不再运行了?
没有输出决定的 PreToolUse hook 会阻止该工具。确保脚本以 echo '{"decision":"allow"}' 结尾并以 0 退出,无论这一行之前发生了什么。
这些通知会发到我的 iPhone 上吗?
不会。macOS 通知只会留在 Mac 上。要通知到手机,请使用 Remote Control、ntfy、聊天应用或 Antigravity Notifier。