gog

gog

熱門

Google Workspace CLI,支援 Gmail、日曆、雲端硬碟、聯絡人、試算表和文件。

38萬星標
8.1萬分支
更新於 2026/7/18
SKILL.md
readonlyread-only
name
gog
description

Google Workspace CLI,支援 Gmail、日曆、雲端硬碟、聯絡人、試算表和文件。

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 不會處理 \n 跳脫字元。如果需要內嵌換行,請使用 heredoc 或 $'Line 1\n\nLine 2'

  • 只有在需要豐富格式時才使用 --body-html

  • HTML 標籤:<p> 段落、<br> 換行、<strong> 粗體、<em> 斜體、<a href="url"> 連結、<ul>/<li> 列表。

  • 範例(從標準輸入的純文字):

    gog gmail send --to recipient@example.com \
      --subject "會議後續" \
      --body-file - <<'EOF'
    嗨,名字:
    
    感謝今天的會議。後續步驟:
    - 項目一
    - 項目二
    
    祝好,
    你的名字
    EOF
    
  • 範例(HTML 列表):

    gog gmail send --to recipient@example.com \
      --subject "會議後續" \
      --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