iMessage
使用 imsg 透過 macOS 的 Messages.app 讀取與傳送 iMessage/SMS 訊息。
先決條件
- macOS,並已登入 Messages.app
- 安裝:
brew install steipete/tap/imsg - 為終端機授予完整磁碟存取權限(系統設定 → 隱私權 → 完整磁碟存取權限)
- 於提示時授予 Messages.app 自動化權限
使用時機
- 使用者要求傳送 iMessage 或簡訊
- 讀取 iMessage 對話記錄
- 查看最近的 Messages.app 聊天
- 傳送訊息至電話號碼或 Apple ID
不應使用時機
- Telegram/Discord/Slack/WhatsApp 訊息 → 請使用對應的閘道頻道
- 群組聊天管理(新增/移除成員)→ 不支援
- 大量/群發訊息 → 務必先徵求使用者同意
快速參考
列出聊天記錄
imsg chats --limit 10 --json
查看歷史記錄
# 依聊天 ID
imsg history --chat-id 1 --limit 20 --json
# 包含附件資訊
imsg history --chat-id 1 --limit 20 --attachments --json
傳送訊息
# 僅文字
imsg send --to "+14155551212" --text "您好!"
# 含附件
imsg send --to "+14155551212" --text "看看這個" --file /path/to/image.jpg
# 強制使用 iMessage 或 SMS
imsg send --to "+14155551212" --text "嗨" --service imessage
imsg send --to "+14155551212" --text "嗨" --service sms
監控新訊息
imsg watch --chat-id 1 --attachments
服務選項
--service imessage— 強制使用 iMessage(需要收件人啟用 iMessage)--service sms— 強制使用 SMS(綠色氣泡)--service auto— 讓 Messages.app 自動決定(預設)
規則
- 在傳送前,務必確認收件人與訊息內容
- 未經使用者明確同意,切勿傳送給未知號碼
- 附加檔案前,請確認檔案路徑存在
- 請勿濫發訊息——請自行限制頻率
範例工作流程
使用者:「傳訊息給老媽說我會晚點到」
# 1. 找到老媽的聊天
imsg chats --limit 20 --json | jq '.[] | select(.displayName | contains("老媽"))'
# 2. 向使用者確認:「找到老媽,號碼為 +1555123456。透過 iMessage 傳送『我會晚點到』?」
# 3. 確認後傳送
imsg send --to "+1555123456" --text "我會晚點到"