Google Workspace CLI 完全攻略 EP1:一行指令管理 Google 日历和待办事项

还在每次都打开浏览器查 Google 日历?GWS 是 Google 最近开源的 CLI 工具,GitHub 上 9 天就冲到 18000 颗星。一行指令直接在终端机拉出所有行程,查行程、排会议、找空档、管待办,全部在终端机搞定。

一、安装 GWS

GWS 用 npm 安装,一行搞定:

Bash
npm install -g @googleworkspace/cli

装完确认一下版本:

Bash
gws --version

认证的部分需要先跑 gws auth setupgws auth login,照着官方文件跑一次就好,不难。

二、查看日历行程

GWS 有一个 calendar 的 helper 指令叫 +agenda,专门用来看行程:

Bash
gws calendar +agenda

它预设就是拉今天的行程,而且所有日历一起来——工作的、个人的、订阅的,全部一次拉出来。

预设输出是 JSON,加个 --format table 变成表格更好读:

Bash
gws calendar +agenda --format table

不管 JSON 还是 table,输出都是结构化的,AI agent 可以直接吃这个 output 去做事。

+agenda 还有几个好用的 flag:

Bash
# 看明天的行程
gws calendar +agenda --tomorrow --format table

# 看未来一整周
gws calendar +agenda --week --format table

# 指定天数,例如未来3天
gws calendar +agenda --days 3 --format table

三、建立日历事件

GWS calendar 有一个 +insert 的 helper 指令,可以快速建事件:

Bash
gws calendar +insert \
  --summary '周会' \
  --start '2026-03-13T14:00:00+08:00' \
  --end '2026-03-13T15:00:00+08:00'

一行指令会议就建好了。回传的 JSON 里面有事件的 ID 跟链接,可以直接点开确认。

要加地点跟说明也行:

Bash
gws calendar +insert \
  --summary '设计Review' \
  --start '2026-03-14T10:00:00+08:00' \
  --end '2026-03-14T11:00:00+08:00' \
  --location '3楼会议室A' \
  --description '讨论Q2新功能的UI设计'

要邀请人的话,用 --attendee,可以重复加:

Bash
gws calendar +insert \
  --summary '项目Kickoff' \
  --start '2026-03-15T09:00:00+08:00' \
  --end '2026-03-15T10:00:00+08:00' \
  --attendee tpjaord@gmail.com

四、修改和删除事件

改时间用 events patch,GWS 不只有 helper,底下的 Google Calendar API 全部都能直接呼叫:

Bash
gws calendar events patch \
  --params '{"calendarId": "primary", "eventId": "事件ID", "sendUpdates": "all"}' \
  --json '{"start": {"dateTime": "2026-03-13T15:00:00+08:00"}, "end": {"dateTime": "2026-03-13T16:00:00+08:00"}}'

patch 就是只改你指定的字段,其他不动。sendUpdatesall 的话,会自动通知被邀请的人。

小技巧:--dry-run 在真的送出去之前先预览一下,它会把 URL 跟 body 印出来给你看,但不会真的送出去。每次改东西之前先 dry-run,就不怕手滑搞砸了。

Bash
gws calendar events patch \
  --params '{"calendarId": "primary", "eventId": "事件ID"}' \
  --json '{"summary": "改名测试"}' \
  --dry-run

删除事件就更直接了:

Bash
gws calendar events delete \
  --params '{"calendarId": "primary", "eventId": "事件ID"}'

五、查询空闲时段(free/busy)

每次乔时间就是一直问「你几点有空」,来回好几次超烦。GWS 一行指令帮你查 free/busy:

Bash
gws calendar freebusy query \
  --json '{
    "timeMin": "2026-03-13T08:00:00+08:00",
    "timeMax": "2026-03-13T18:00:00+08:00",
    "items": [
      {"id": "tpjaord@gmail.com"}
    ]
  }'

每个人什么时候有事全部列出来,空的时段就是大家都有空的时间。一次查三个人、五个人都行,特别是跨时区的团队,这招超好用。

六、Tasks 待办事项管理

Google Tasks 跟日历是绑在一起的,待办事项直接显示在日历上面。用 CLI 操作超快。

先看你有哪些任务清单:

Bash
gws tasks tasklists list --format table

建一个新的清单:

Bash
gws tasks tasklists insert --json '{"title": "Q2目标"}'

拿到清单 ID 之后,往里面加任务:

Bash
gws tasks tasks insert \
  --params '{"tasklist": "清单ID"}' \
  --json '{"title": "Review Q1数据", "notes": "从Analytics拉报表", "due": "2026-03-16T00:00:00Z"}'

查看清单里所有任务:

Bash
gws tasks tasks list --params '{"tasklist": "清单ID"}' --format table

任务完成了要标记也很简单,用 patch:

Bash
gws tasks tasks patch \
  --params '{"tasklist": "清单ID", "task": "任务ID"}' \
  --json '{"status": "completed"}'

七、大招:schema introspection

GWS 有一个 schema 指令,可以查任何 API 方法的参数和格式:

Bash
gws schema calendar.events.list

什么参数是必填的、类型是什么、回传长什么样,全部都列出来了。根本不用去翻 Google 的 API 文档。

对 Tasks 也一样能用:

Bash
gws schema tasks.tasks.insert

GWS 的 --help 也很好用,每一层都能看:

Bash
gws calendar --help
gws calendar events --help
gws calendar events list --help

--help 看有什么指令,schema 看怎么用。这招学起来,日历、试算表、Docs,什么服务你都能自己摸出来。

八、总结

功能 指令 说明
查行程 +agenda 支持 today、week、days、calendar 过滤
建事件 +insert 支持地点、说明、邀请人
改事件 events patch 只改指定字段,其他不动
删事件 events delete 直接删除指定事件
预览 --dry-run 先预览再执行,不怕手滑
查空档 freebusy query 一次查多人空闲时段
管待办 tasks tasklists 跟 tasks CRUD
查参数 schema 查任何 API 的参数格式