gog gog

gog 是一个强大的 Google Workspace 命令行接口工具,用于高效管理 Gmail、日历、云端硬盘、联系人、表格和文档。它通过 OAuth 认证,提供脚本化操作、批量处理和自动化工作流,是开发者和系统管理员提升 Google 服务管理效率的利器。关键词:Google Workspace CLI,Gmail 命令行,日历管理,云端硬盘 API,表格自动化,文档导出,OAuth 工具,DevOps 自动化。

DevOps 0 次安装 0 次浏览 更新于 2/24/2026

name: gog description: Google Workspace CLI for Gmail, Calendar, Drive, Contacts, Sheets, and Docs. homepage: https://gogcli.sh metadata: { “openclaw”: { “emoji”: “🎮”, “requires”: { “bins”: [“gog”] }, “install”: [ { “id”: “brew”, “kind”: “brew”, “formula”: “steipete/tap/gogcli”, “bins”: [“gog”], “label”: “安装 gog (brew)”, }, ], }, }

gog

使用 gog 命令行工具管理 Gmail、日历、云端硬盘、联系人、表格和文档。需要 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

常用命令

  • Gmail 搜索:gog gmail search 'newer_than:7d' --max 10
  • Gmail 邮件搜索(按邮件,忽略线程):gog gmail messages search "in:inbox from:ryanair.com" --max 20 --account you@example.com
  • Gmail 发送(纯文本):gog gmail send --to a@b.com --subject "Hi" --body "Hello"
  • Gmail 发送(多行):gog gmail send --to a@b.com --subject "Hi" --body-file ./message.txt
  • Gmail 发送(标准输入):gog gmail send --to a@b.com --subject "Hi" --body-file -
  • Gmail 发送(HTML):gog gmail send --to a@b.com --subject "Hi" --body-html "<p>Hello</p>"
  • Gmail 创建草稿:gog gmail drafts create --to a@b.com --subject "Hi" --body-file ./message.txt
  • Gmail 发送草稿:gog gmail drafts send <draftId>
  • Gmail 回复:gog gmail send --to a@b.com --subject "Re: Hi" --body "Reply" --reply-to-message-id <msgId>
  • 日历列出事件:gog calendar events <calendarId> --from <iso> --to <iso>
  • 日历创建事件:gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso>
  • 日历创建带颜色事件:gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso> --event-color 7
  • 日历更新事件:gog calendar update <calendarId> <eventId> --summary "New Title" --event-color 4
  • 日历显示颜色:gog calendar colors
  • 云端硬盘搜索:gog drive search "query" --max 10
  • 联系人:gog contacts list --max 20
  • 表格获取:gog sheets get <sheetId> "Tab!A1:D10" --json
  • 表格更新:gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]' --input USER_ENTERED
  • 表格追加:gog sheets append <sheetId> "Tab!A:C" --values-json '[["x","y","z"]]' --insert INSERT_ROWS
  • 表格清除:gog sheets clear <sheetId> "Tab!A2:Z"
  • 表格元数据:gog sheets metadata <sheetId> --json
  • 文档导出:gog docs export <docId> --format txt --out /tmp/doc.txt
  • 文档查看:gog docs cat <docId>

日历颜色

  • 使用 gog calendar colors 查看所有可用事件颜色(ID 1-11)
  • 使用 --event-color <id> 标志为事件添加颜色
  • 事件颜色 ID(来自 gog calendar colors 输出):
    • 1: #a4bdfc
    • 2: #7ae7bf
    • 3: #dbadff
    • 4: #ff887c
    • 5: #fbd75b
    • 6: #ffb878
    • 7: #46d6db
    • 8: #e1e1e1
    • 9: #5484ed
    • 10: #51b749
    • 11: #dc2127

邮件格式

  • 首选纯文本。使用 --body-file 处理多段落消息(或使用 --body-file - 从标准输入读取)。
  • 相同的 --body-file 模式适用于草稿和回复。
  • --body 不会对 进行转义。如果需要内联换行,请使用 heredoc 或 `$'Line 1

Line 2’`。

  • 仅在需要丰富格式时使用 --body-html

  • HTML 标签:<p> 用于段落,<br> 用于换行,<strong> 用于加粗,<em> 用于斜体,<a href="url"> 用于链接,<ul>/<li> 用于列表。

  • 示例(通过标准输入的纯文本):

    gog gmail send --to recipient@example.com \
      --subject "Meeting Follow-up" \
      --body-file - <<'EOF'
    你好 [姓名],
    
    感谢今天的会议。后续步骤:
    - 事项一
    - 事项二
    
    此致,
    你的名字
    EOF
    
  • 示例(HTML 列表):

    gog gmail send --to recipient@example.com \
      --subject "Meeting Follow-up" \
      --body-html "<p>你好 [姓名],</p><p>感谢今天的会议。以下是后续步骤:</p><ul><li>事项一</li><li>事项二</li></ul><p>此致,<br>你的名字</p>"
    

注意事项

  • 设置 GOG_ACCOUNT=you@gmail.com 环境变量以避免重复使用 --account
  • 对于脚本编写,建议使用 --json--no-input
  • 表格值可以通过 --values-json 传递(推荐)或作为内联行。
  • 文档支持导出/查看/复制。原地编辑需要 Docs API 客户端(gog 不支持)。
  • 发送邮件或创建事件前请确认。
  • gog gmail search 每个线程返回一行;当需要单独返回每封邮件时,请使用 gog gmail messages search