iMessage
使用 imsg 读取和发送 iMessage/SMS,通过 macOS 的 Messages.app 进行操作。
前提条件
- 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 "我晚点到"