Google Tasks CLI Skill
This skill enables you to manage Google Tasks directly from the command line using the gtasks CLI tool.
Prerequisites
Before using any commands, ensure the following requirements are met:
1. GTasks Installation
Check if gtasks is installed on the system:
CODEBLOCK0
If gtasks is not installed:
- 1. Download the binary for your system from GitHub Releases
- Install it:
-
macOS/Linux: Move to
/usr/local/bin or add to PATH
-
Windows: Add to a folder in your PATH environment variable
- 3. Verify installation: INLINECODE2
IMPORTANT for Agents: Always check if gtasks is installed before attempting to use it. If the command is not found, inform the user and provide installation instructions.
2. Environment Variables
Set up Google OAuth2 credentials as environment variables:
CODEBLOCK1
How to get credentials:
- 1. Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Tasks API
- Create OAuth2 credentials (Application type: "Desktop app")
- Note the authorized redirect URIs that gtasks uses:
-
http://localhost:8080/callback
-
http://localhost:8081/callback
-
http://localhost:8082/callback
-
http://localhost:9090/callback
- INLINECODE7
For persistent setup, use a secrets manager or a ~/.env file with restrictive permissions — do not commit these values to version control or add them to shared shell profile files:
CODEBLOCK2
2. Authentication
Once environment variables are set, authenticate with Google:
CODEBLOCK3
This will open a browser for OAuth2 authentication. The token is stored in ~/.gtasks/token.json with 0600 permissions. Verify with ls -la ~/.gtasks/token.json. If you no longer need access, run gtasks logout to revoke and delete the token.
Core Concepts
- - Task Lists: Containers that hold tasks (like "Work", "Personal", "Shopping")
- Tasks: Individual to-do items within a task list
- Task Properties: Title (required), notes/description (optional), due date (optional), status (pending/completed)
Command Structure
All commands follow this pattern:
CODEBLOCK4
Authentication
Login
gtasks login
Opens browser for Google OAuth2 authentication. Required before using any other commands.
Logout
gtasks logout
Removes stored credentials from
~/.gtasks/token.json.
Task List Management
View All Task Lists
gtasks tasklists view
Displays all task lists with numbered indices.
Output Example:
CODEBLOCK8
Create a Task List
gtasks tasklists add -t "Work Projects"
gtasks tasklists add --title "Shopping List"
Creates a new task list with the specified title.
Flags:
- -
-t, --title: Task list title (required)
Delete a Task List
gtasks tasklists rm
Interactive prompt to select and delete a task list.
Update Task List Title
gtasks tasklists update -t "New Title"
Interactive prompt to select a task list and update its title.
Flags:
- -
-t, --title: New title for the task list (required)
Task Management
All task commands can optionally specify a task list using the -l flag. If omitted, you'll be prompted to select one interactively.
View Tasks
Basic view:
CODEBLOCK12
Include completed tasks:
CODEBLOCK13
Show only completed tasks:
CODEBLOCK14
Sort tasks:
CODEBLOCK15
Output formats:
CODEBLOCK16
Table Output Example:
CODEBLOCK17
JSON Output Example:
CODEBLOCK18
Create a Task
Interactive mode:
gtasks tasks add
gtasks tasks add -l "Work"
Prompts for title, notes, and due date.
Flag mode:
CODEBLOCK20
Flags:
- -
-t, --title: Task title (required for non-interactive mode) - INLINECODE17 : Task notes/description (optional)
- INLINECODE18 : Due date (optional, flexible format)
Date Format Examples:
The date parser supports many formats:
- -
2024-12-25 (ISO format) - INLINECODE20
- INLINECODE21
- INLINECODE22
- INLINECODE23
- INLINECODE24
See dateparse examples for all supported formats.
Mark Task as Complete
With task number:
CODEBLOCK21
Interactive mode:
gtasks tasks done
gtasks tasks done -l "Personal"
Prompts to select a task from the list.
Delete a Task
With task number:
CODEBLOCK23
Interactive mode:
gtasks tasks rm
gtasks tasks rm -l "Work"
Prompts to select a task to delete.
View Task Details
With task number:
CODEBLOCK25
Interactive mode:
CODEBLOCK26
Output Example:
CODEBLOCK27
Common Workflows
Quick Task Creation
When a user says "add a task to my work list":
CODEBLOCK28
Check Today's Tasks
CODEBLOCK29
Complete Multiple Tasks
CODEBLOCK30
View All Tasks Across Lists
Run view command multiple times for each list, or first list all task lists:
CODEBLOCK31
Export Tasks
CODEBLOCK32
Best Practices
- 1. Always check authentication first: If commands fail with authentication errors, run INLINECODE25
- 2. Use task list flag for automation: When scripting or when the user specifies a list name, use
-l flag to avoid interactive prompts
- 3. Leverage flexible date parsing: The
--due flag accepts natural language dates like "tomorrow", "next week", etc.
- 4. Use appropriate output format:
- Table format for human-readable output
- JSON for parsing/integration with other tools
- CSV for spreadsheet import
- 5. Task numbers are ephemeral: Task numbers change when tasks are added, completed, or deleted. Always view the list first to get current numbers.
- 6. Handle missing lists gracefully: If a user specifies a non-existent list name, the command will error. Always verify list names first with
gtasks tasklists view.
Error Handling
Common errors and solutions:
- - "Failed to get service" or Authentication errors:
- First, ensure environment variables are set:
echo $GTASKS_CLIENT_ID
- If variables are not set, export them (see Prerequisites section)
- Then run
gtasks login to authenticate
- - "incorrect task-list name": The specified list name doesn't exist. Use
gtasks tasklists view to see available lists - "Incorrect task number": The task number is invalid. Use
gtasks tasks view to see current task numbers - "Date format incorrect": The date string couldn't be parsed. Use formats like "2024-12-25", "tomorrow", or "Dec 25"
Examples
Example 1: Create a shopping list and add items
CODEBLOCK33
Example 2: Review and complete work tasks
CODEBLOCK34
Example 3: Add task with deadline
CODEBLOCK35
Example 4: Export completed tasks
CODEBLOCK36
Tips for Agents
Before Running Any Commands
- 1. Check gtasks installation first:
# Try to run gtasks version check
gtasks --version 2>/dev/null || gtasks.exe --version 2>/dev/null
If this fails, inform the user that gtasks is not installed and provide installation instructions from the Prerequisites section.
- 2. Verify environment variables are set:
CODEBLOCK38
- 3. Check authentication status:
CODEBLOCK39
General Tips
- - When the user mentions "tasks" without specifying a tool, ask if they want to use Google Tasks
- If the user asks about their tasks, first run
gtasks tasklists view to see available lists - Always confirm which task list to use if not specified by the user
- When creating tasks with dates, prefer explicit date formats (YYYY-MM-DD) over relative terms for clarity
- Remember that task numbers are 1-indexed and change after modifications
- If a command requires interaction but you're running non-interactively, use flags to provide all required information
Google Tasks CLI 技能
此技能使您能够通过 gtasks CLI 工具直接从命令行管理 Google Tasks。
前提条件
在使用任何命令之前,请确保满足以下要求:
1. GTasks 安装
检查系统上是否安装了 gtasks:
bash
跨平台检查(适用于 macOS、Linux、Windows Git Bash)
gtasks --version 2>/dev/null || gtasks.exe --version 2>/dev/null || echo 未找到 gtasks
或使用 which/where 命令
macOS/Linux:
which gtasks
Windows(命令提示符):
where gtasks
Windows(PowerShell):
Get-Command gtasks
如果未安装 gtasks:
- 1. 从 GitHub Releases 下载适用于您系统的二进制文件
- 安装它:
-
macOS/Linux:移动到 /usr/local/bin 或添加到 PATH
-
Windows:添加到 PATH 环境变量中的文件夹
- 3. 验证安装:gtasks --version
对代理程序的重要提示: 在尝试使用 gtasks 之前,始终检查它是否已安装。如果未找到该命令,请告知用户并提供安装说明。
2. 环境变量
将 Google OAuth2 凭据设置为环境变量:
bash
export GTASKSCLIENTID=your-client-id.apps.googleusercontent.com
export GTASKSCLIENTSECRET=your-client-secret
如何获取凭据:
- 1. 前往 Google Cloud Console
- 创建新项目或选择现有项目
- 启用 Google Tasks API
- 创建 OAuth2 凭据(应用程序类型:桌面应用)
- 注意 gtasks 使用的授权重定向 URI:
- http://localhost:8080/callback
- http://localhost:8081/callback
- http://localhost:8082/callback
- http://localhost:9090/callback
- http://localhost:9091/callback
对于持久化设置,请使用密钥管理器或具有限制性权限的 ~/.env 文件——不要将这些值提交到版本控制或添加到共享的 shell 配置文件:
bash
推荐:存储在具有限制权限的文件中
echo export GTASKS
CLIENTID=your-client-id >> ~/.gtasks_env
echo export GTASKS
CLIENTSECRET=your-client-secret >> ~/.gtasks_env
chmod 600 ~/.gtasks_env
从您的 shell 配置文件中引用
echo source ~/.gtasks_env >> ~/.zshrc
2. 身份验证
设置环境变量后,使用 Google 进行身份验证:
bash
gtasks login
这将打开浏览器进行 OAuth2 身份验证。令牌存储在 ~/.gtasks/token.json 中,权限为 0600。使用 ls -la ~/.gtasks/token.json 验证。如果您不再需要访问权限,请运行 gtasks logout 以撤销并删除令牌。
核心概念
- - 任务列表:包含任务的容器(如工作、个人、购物)
- 任务:任务列表中的单个待办事项
- 任务属性:标题(必需)、备注/描述(可选)、截止日期(可选)、状态(待处理/已完成)
命令结构
所有命令遵循此模式:
gtasks [命令] [子命令] [标志] [参数]
身份验证
登录
bash
gtasks login
打开浏览器进行 Google OAuth2 身份验证。在使用任何其他命令之前需要执行此操作。
登出
bash
gtasks logout
从 ~/.gtasks/token.json 中移除存储的凭据。
任务列表管理
查看所有任务列表
bash
gtasks tasklists view
显示所有任务列表及其编号索引。
输出示例:
[1] 我的任务
[2] 工作
[3] 个人
创建任务列表
bash
gtasks tasklists add -t 工作项目
gtasks tasklists add --title 购物清单
使用指定的标题创建新任务列表。
标志:
删除任务列表
bash
gtasks tasklists rm
交互式提示选择并删除任务列表。
更新任务列表标题
bash
gtasks tasklists update -t 新标题
交互式提示选择任务列表并更新其标题。
标志:
- - -t, --title:任务列表的新标题(必需)
任务管理
所有任务命令都可以使用 -l 标志可选地指定任务列表。如果省略,将提示您交互式选择。
查看任务
基本视图:
bash
gtasks tasks view
gtasks tasks view -l 工作
包含已完成的任务:
bash
gtasks tasks view --include-completed
gtasks tasks view -i
仅显示已完成的任务:
bash
gtasks tasks view --completed
排序任务:
bash
gtasks tasks view --sort=due # 按截止日期排序
gtasks tasks view --sort=title # 按标题排序
gtasks tasks view --sort=position # 按位置排序(默认)
输出格式:
bash
gtasks tasks view --format=table # 表格格式(默认)
gtasks tasks view --format=json # JSON 输出
gtasks tasks view --format=csv # CSV 输出
表格输出示例:
工作中的任务:
编号 标题 描述 状态 截止日期
1 完成报告 Q4 分析 待处理 2024年12月25日
2 团队会议 每周同步 待处理 -
3 代码审查 PR #123 已完成 2024年12月20日
JSON 输出示例:
json
[
{
number: 1,
title: 完成报告,
description: Q4 分析,
status: 待处理,
due: 2024-12-25
}
]
创建任务
交互模式:
bash
gtasks tasks add
gtasks tasks add -l 工作
提示输入标题、备注和截止日期。
标志模式:
bash
gtasks tasks add -t 购买杂货
gtasks tasks add -t 完成报告 -n Q4 分析 -d 2024-12-25
gtasks tasks add -t 给牙医打电话 -d 明天
gtasks tasks add -t 团队会议 -d 12月25日
标志:
- - -t, --title:任务标题(非交互模式必需)
- -n, --note:任务备注/描述(可选)
- -d, --due:截止日期(可选,灵活格式)
日期格式示例:
日期解析器支持多种格式:
- - 2024-12-25(ISO 格式)
- 2024年12月25日
- 12月25日
- 明天
- 下周五
- 12/25/2024
有关所有支持的格式,请参阅 dateparse 示例。
将任务标记为已完成
使用任务编号:
bash
gtasks tasks done 1
gtasks tasks done 3 -l 工作
交互模式:
bash
gtasks tasks done
gtasks tasks done -l 个人
提示从列表中选择任务。
删除任务
使用任务编号:
bash
gtasks tasks rm 2
gtasks tasks rm 1 -l 购物
交互模式:
bash
gtasks tasks rm
gtasks tasks rm -l 工作
提示选择要删除的任务。
查看任务详情
使用任务编号:
bash
gtasks tasks info 1
gtasks tasks info 3 -l 工作
交互模式:
bash
gtasks tasks info
gtasks tasks info -l 个人
输出示例:
任务:完成报告
状态:需要操作
截止日期:2024年12月25日
备注:完成 Q4 分析并提交给经理
链接:
- https://docs.google.com/document/d/...
在 Google Tasks 中查看:https://tasks.google.com/...
常见工作流程
快速创建任务
当用户说添加一个任务到我的工作列表时:
bash
gtasks tasks add -l 工作 -t 任务标题
检查今天的任务
bash
gtasks tasks view --sort=due
完成多个任务
bash
gtasks tasks done -