自动化与脚本
需要用 gog/gogcli 从命令行安全、可脚本化地操作…
当用户提到 gog/gogcli/Google CLI,或用命令行、JSON 优先方式操作 Gmail、Calendar、Drive、Docs、Sheets、Slides、Forms、Apps Script、Chat、Classroom、Contacts、Tasks、People、Groups、Admin、Keep 时适用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 59/100 ×0.15
适用场景
需要用 gog/gogcli 从命令行安特定
解决思路
- 以 https://github.com/steipete/gogcli 为权威上游;当精确语法重要时,运行 `gog <command> --help` 或 `gog schema --json`,因为命令面变化很快。
- 检查和脚本优先使用 `gog --json ... | jq ...`。
- 仅当稳定的 TSV 比 JSON 更方便时使用 `--plain`。
- 对支持的写操作,在准备变更或用户意图不明确时使用 `--dry-run`。
- 在自动化中使用 `--no-input`,让命令失败而不是交互提示。
- 仅当用户要求破坏性/公开/发送/管理操作,或已清楚解释影响后,才使用 `--force`。
- 不要静默修复 OAuth、同意、keyring 或 Workspace delegation 问题;向用户展示应运行的确切命令。
- 除非用户明确要求,不要导出 token、打印 secret、开启公开分享、添加 delegate/forwarding、发送邮件、暂停用户或永久删除数据。
- 对必须不发送邮件的 agent 运行,添加 `--gmail-no-send`、设置 `GOG_GMAIL_NO_SEND=1`,或配置 `gog config no-send set <account>`。
- 安装:`brew install gogcli`。
- 设置 OAuth 凭据:`gog auth credentials set ~/Downloads/client_secret_....json`。
- 添加账户并请求服务:`gog auth add you@example.com --services gmail,calendar,drive`。
- 检查认证:`gog auth list --check`。
- Homebrew 现在使用 `brew install gogcli`;旧 tap 示例已过时。
- `gog auth add` 默认 `--services user`;按任务请求所需 services。
- `--services all` 仅作为 `user` 的向后兼容别名被接受;需要每个 API 时不要使用它。
- 使用 `--readonly`、`--drive-scope readonly|file|full` 和 `--gmail-scope readonly|full` 实现最小权限。
- Keep 和 Admin 需要 Workspace service-account/domain-wide delegation;Google Chat、Groups、directory 和 Classroom 也有 Workspace 限制。
- 对 headless/CI,考虑 `--manual`、`--remote`、`--access-token` 或 `GOG_AUTH_MODE=adc`。
- 阅读 `references/authentication.md` 获取完整认证模式。
- 全局标志:`--account, -a <email|alias|auto>`(账户选择);`--client <name>`(命名 OAuth client/token bucket);`--access-token <token>`(直接短期 token,也支持 `GOG_ACCESS_TOKEN`);`--json, -j`(机器可读 JSON);`--plain, -p`(稳定 TSV);`--results-only`(仅 JSON 主结果);`--select <fields>`(尽力 JSON 投影);`--dry-run, -n`(预览支持的写操作);`--force, -y`(跳过确认);`--no-input`(永不提示);`--enable-commands <csv>`(允许顶层或点分命令白名单);`--disable-commands <csv>`(禁止顶层或点分命令黑名单);`--gmail-no-send`(阻止 Gmail 发送操作);`--verbose, -v`(调试日志)。
- 有用命令别名:`gog send ...`(`gog gmail send` 别名);`gog ls`(`gog drive ls` 别名);`gog search "budget"`(`gog drive search` 别名);`gog download <fileId>`(`gog drive download` 别名);`gog upload ./file.pdf`(`gog drive upload` 别名);`gog me`(`gog people me` 别名);`gog status`(`gog auth status` 别名);`gog open <id-or-url>`(尽力打开 Google web URL,离线)。
- 账户选择:`gog auth alias set work you@company.com`。
- 使用别名搜索:`gog --account work gmail search 'is:unread newer_than:2d'`。
- 用环境变量选择账户:`GOG_ACCOUNT=work gog calendar events primary --today`。
- 为命名 client 设置凭据:`gog --client work auth credentials set ~/Downloads/work-client.json`。
- 为命名 client 添加账户:`gog --client work auth add you@company.com --services gmail,calendar`。
- Gmail 搜索并提取 thread id:`gog --json gmail search 'is:unread newer_than:7d' | jq -r '.threads[].id'`。
- 搜索带正文:`gog gmail messages search 'from:alice@example.com has:attachment' --include-body`。
- 搜索完整消息:`gog gmail messages search 'subject:report newer_than:30d' --full`。
- 获取 thread 并下载附件:`gog gmail thread get <threadId> --download --out-dir ./attachments`。
- 修改 thread 标签:`gog gmail labels modify <threadId> --add Project --remove INBOX`。
- 修改 message 标签:`gog gmail messages modify <messageId> --add STARRED`。
- 发送邮件:`gog gmail send --to user@example.com --subject "Hello" --body-file ./body.txt`。
- 转发邮件:`gog gmail forward <messageId> --to user@example.com --note "FYI"`。
- 对 forwarding、autoreply、watch/Pub/Sub、filters、delegates、send-as、label colours、batch operations 和 tracking,阅读 `references/gmail.md`。
- Calendar 列出日历:`gog calendar calendars`。
- Calendar 查看今天事件:`gog calendar events primary --today --weekday`。
- Calendar 按时间范围查看所有事件:`gog calendar events --all --from "2026-04-25T00:00:00+02:00" --to "2026-04-26T00:00:00+02:00"`。
- Calendar freebusy:`gog calendar freebusy --cal primary --from "2026-04-25T09:00:00+02:00" --to "2026-04-25T17:00:00+02:00"`。
- Calendar 创建事件:`gog calendar create primary --summary "Planning" --from "2026-04-25T14:00:00+02:00" --to "2026-04-25T14:30:00+02:00" --attendees "alice@example.com,bob@example.com" --with-meet`。
- Calendar 回应事件:`gog calendar respond primary <eventId> --status accepted --send-updates all`。
- 生成的 datetime 使用带时区偏移的 RFC3339;对 aliases、subscriptions、secondary calendars、extended properties、Focus Time、OOO、working locations、team calendars 和 conflict detection,阅读 `references/calendar.md`。
- Drive 搜索:`gog drive search "invoice filetype:pdf" --max 20`。
- Drive 上传并转换:`gog drive upload ./report.md --convert-to doc --parent <folderId>`。
- Drive 替换文件:`gog drive upload ./deck.pdf --replace <fileId> --name "Board Deck.pdf"`。
- Drive 分享:`gog drive share <fileId> --to user --email editor@example.com --role commenter`。
- Docs 写入/替换 Markdown:`gog docs write <docId> --file ./brief.md --replace --markdown`。
- Docs sed 预览:`gog docs sed <docId> 's/status/{b c=green}approved/g' --dry-run`。
- Sheets 更新:`gog sheets update <spreadsheetId> 'Sheet1!A1' '[["Name","Score"],["Ada",98]]'`。
- Sheets 图表列表:`gog sheets chart list <spreadsheetId>`。
- Slides 缩略图:`gog slides thumbnail <presentationId> <slideId> --out ./slide.png`。
- Forms 回复列表:`gog forms responses list <formId> --max 20`。
- Apps Script 运行函数:`gog appscript run <scriptId> myFunction --params '["arg1", 123]'`。
- 阅读 `references/drive-docs.md` 获取当前 file/content 命令;Docs sed 格式化阅读 `references/sedmat.md`。
- Contacts 搜索:`gog contacts search "Ada"`。
- Tasks 列出任务列表:`gog tasks lists`。
- Tasks 添加任务:`gog tasks add <tasklistId> --title "Weekly review" --due "2026-04-27" --repeat weekly`。
- Chat 发送消息:`gog chat messages send spaces/<spaceId> --text "Build complete"`。
- Groups 成员:`gog groups members engineering@example.com`。
- Admin 用户列表:`gog admin users list --domain example.com`。
- Keep 搜索:`gog keep search "receipt"`。
- 阅读 `references/other-services.md` 获取 Chat、Classroom、Contacts、Tasks、People、Groups、Admin、Keep 和时间工具。
- 检查 JSON 形状:`gog --json gmail search 'is:unread' --max 3 | jq .`。
- 使用分页/全页:`gog --json calendar events primary --from today --to tomorrow --all-pages`。
- 受支持的列表命令无结果时干净失败:`gog --json calendar events primary --query "unlikely query" --fail-empty`。
- 检查输出后用 xargs 批处理:`gog --json gmail search 'older_than:1y label:newsletter' --max 200 | jq -r '.threads[].id' | xargs -n 50 gog gmail labels modify --remove INBOX`。
- agent-safe 命令面:`GOG_ENABLE_COMMANDS=calendar.events,calendar.freebusy,tasks gog --no-input --json calendar events primary --today`。
- 参考地图:`references/command-reference.md` 由 `gog schema --json` 生成的命令索引;`references/authentication.md` OAuth clients、service accounts、scopes、keyrings、headless auth;`references/configuration.md` config keys、环境变量、输出模式、安全开关;`references/gmail.md` Gmail search、read、send、labels、settings、watch、tracking、autoreply;`references/calendar.md` Calendar listing、event writes、scheduling、special events、aliases;`references/drive-docs.md` Drive、Docs、Sheets、Slides、Forms、Apps Script;`references/sedmat.md` Docs sed/formatting DSL;`references/other-services.md` Chat、Classroom、Contacts、Tasks、People、Groups、Admin、Keep。
适用边界 · 注意事项
- 未安装或无法配置 gog/gogcli,或没有 Google Workspace/OAuth 授权时,不应使用此技能。
- 需要图形界面操作、非 Google 服务或非 gog/gogcli 命令行的自动化时,不适用。
- 用户未明确要求发送邮件、公开分享、添加委托/转发、暂停用户或永久删除数据等敏感操作时,不应执行这些操作。