在 macOS 上,要在 Google Antigravity 完成時收到通知,最簡單的方式是在 ~/.gemini/config/hooks.json 中加入一個 Stop hook,執行呼叫 osascript -e 'display notification ...' 的腳本。它在你執行 agy 的任何終端機中都能運作,而且不需信任步驟,下一個工作階段起就會執行。請在系統設定中允許 Script Editor 發送通知,否則第一則提醒常常會無聲無息地被丟掉。如果想要可點擊、能把終端機帶到最前面的提醒,請改用 Homebrew 的 terminal-notifier。
01Mac 上的 hook 檔案
Antigravity 的全域 hook 檔案是 ~/.gemini/config/hooks.json,也就是 /Users/you/.gemini/config/hooks.json。agy 命令列、桌面 App 和 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允許 Script Editor 發送通知
osascript 的通知會以 Script Editor 的名義顯示。在全新的 Mac 上,第一則通知常常會被默默丟掉。解決方法:
- 在 Terminal 中執行
osascript -e 'display notification "test" with title "Antigravity"'。 - 開啟系統設定 > 通知,找到 Script Editor,然後開啟允許通知。如果想讓它一直留在螢幕上直到你關閉,請選擇提示。
- 確認沒有專注模式把它隱藏起來(見下文)。
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 採用 fail-closed,所以沒有輸出決定、執行失敗或逾時的 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專注模式與勿擾模式
專注模式會隱藏不在允許清單中的 App 所發出的通知。如果專注模式關閉時提醒會出現、開啟時就消失,請開啟系統設定 > 專注模式,選擇該模式,並把 Script Editor(用於 osascript)或 terminal-notifier 加入允許的 App。如果你希望專注時 Antigravity 保持安靜,就不要把它們加入清單。
08或者交給 antigravity-notifier
Mac 通知只會留在 Mac 上。要在手機上收到提醒並直接在手機上回答,Antigravity Notifier 的免費工具 antigravity-notifier 會在 Mac、Windows 和 Linux 上幫你設定好 hook:
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 App 配對後,你會收到附上最後一則訊息的「Antigravity 已完成」、在你不在時可以允許或拒絕的指令、要回答的 Antigravity 提問,以及輸入下一個指示的輸入框。在 Mac 上,螢幕一鎖定就立即視為不在;如果螢幕未鎖定且你在過去 30 秒內有輸入,就不會等待手機回應。在 iPhone 上,鎖定畫面卡片會顯示目前的步驟,以及變更的檔案和行數。它可在任何終端機中搭配 agy 使用;目前尚不支援桌面 App 和 IDE。
Antigravity Notifier 是由 TouchTap Ltd 開發的獨立工具,與 Google 無關。Google 免費的 Remote Control 是另一種從手機瀏覽器接收通知的方式。App 的價格請見價格。
09常見問題
Antigravity 會自己顯示 macOS 通知嗎?
我們尚未確認桌面 App 或 IDE 本身會顯示什麼。在 agy 命令列中,hook 是取得通知最可靠的方式。
我的腳本在 Terminal 中可以執行,從 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、聊天 App 或 Antigravity Notifier。