gog 是一个 Google Workspace 命令行工具,用于在终端中操作 Gmail、Calendar、Drive、Contacts、Sheets 和 Docs。
用途与主要能力:可搜索与发送 Gmail 邮件、创建和发送草稿、回复邮件;列出与创建日历事件、更新事件及设置事件颜色;搜索云盘文件;列出通讯录;读写与追加、清空 Google 表格数据、读取表格元数据;导出或查看文档内容。
使用方式:首次使用需完成 OAuth 配置,运行 gog auth credentials /path/to/client_secret.json,再执行 gog auth add you@gmail.com --services gmail,calendar,drive,contacts,docs,sheets,之后可用 gog auth list 查看授权。常用命令包括 gog gmail search 'newer_than:7d' --max 10、gog gmail send --to a@b.com --subject "Hi" --body "Hello"、gog calendar events <calendarId> --from <iso> --to <iso>、gog drive search "query" --max 10、gog contacts list --max 20、gog sheets get <sheetId> "Tab!A1:D10" --json、gog docs cat <docId> 等。设置 GOG_ACCOUNT 可免去重复指定 --account,脚本场景建议使用 --json 与 --no-input。
邮件格式:建议优先使用纯文本,多段内容用 --body-file(或 --body-file - 读取标准输入);--body 不会转义 \n,需要换行建议用 heredoc 或 $'Line 1\n\nLine 2';仅在需要富文本时使用 --body-html。
限制:文档支持导出、查看与复制,原地编辑需 Docs API 客户端,gog 不提供。发送邮件或创建事件前应确认。gog gmail search 每条线程返回一行,如需每封邮件单独返回,应使用 gog gmail messages search。日历事件颜色可用 gog calendar colors 查看,通过 --event-color <id> 设置。