home / skills / henkisdabro / wookstar-claude-plugins / google-apps-script

This skill helps you automate Google Workspace tasks with Apps Script, enabling efficient management of Sheets, Docs, Gmail, Drive, Calendar, and more.

npx playbooks add skill henkisdabro/wookstar-claude-plugins --skill google-apps-script

Review the files below or copy the command above to add this skill to your agents.

Files (8)
SKILL.md
5.2 KB
---
name: google-apps-script
description: Comprehensive guide for Google Apps Script development covering all built-in services (SpreadsheetApp, DocumentApp, GmailApp, DriveApp, CalendarApp, FormApp, SlidesApp), triggers, authorization, error handling, and performance optimization. Use when automating Google Sheets operations, creating Google Docs, managing Gmail/email, working with Google Drive files, automating Calendar events, implementing triggers (time-based, event-based), building custom functions, creating add-ons, handling OAuth scopes, optimizing Apps Script performance, working with UrlFetchApp for API calls, using PropertiesService for persistent storage, or implementing CacheService for temporary data. Covers batch operations, error recovery, and JavaScript ES6+ runtime.
---

# Google Apps Script

## Overview

Cloud-based JavaScript platform for automating Google Workspace services. Server-side V8 runtime with automatic OAuth integration across Sheets, Docs, Gmail, Drive, Calendar, and more.

## When to Use This Skill

Invoke this skill when:

- Automating Google Sheets operations (reading, writing, formatting)
- Creating or editing Google Docs programmatically
- Managing Gmail messages and sending emails
- Working with Google Drive files and folders
- Automating Google Calendar events
- Implementing triggers (time-based or event-based)
- Building custom functions for Sheets
- Creating Google Workspace add-ons
- Handling OAuth scopes and authorisation
- Making HTTP requests to external APIs with UrlFetchApp
- Using persistent storage with PropertiesService
- Implementing caching strategies with CacheService
- Optimising performance with batch operations
- Debugging Apps Script code or authorisation issues

## Core Services

1. **SpreadsheetApp** - Google Sheets automation (read, write, format, data validation)
2. **DocumentApp** - Google Docs creation and editing
3. **GmailApp & MailApp** - Email operations (send, search, manage labels)
4. **DriveApp** - File and folder management, sharing, permissions
5. **CalendarApp** - Calendar events, recurring appointments, reminders
6. **Triggers & ScriptApp** - Time-based and event-driven automation

## Quick Start

```javascript
function generateWeeklyReport() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('Data');
  const data = sheet.getRange('A2:D').getValues();

  const report = data.filter(row => row[0]);
  const summarySheet = ss.getSheetByName('Summary') || ss.insertSheet('Summary');
  summarySheet.clear();
  summarySheet.appendRow(['Name', 'Value', 'Status']);
  report.forEach(row => summarySheet.appendRow([row[0], row[1], row[2]]));

  MailApp.sendEmail({
    to: Session.getEffectiveUser().getEmail(),
    subject: 'Weekly Report Generated',
    body: `Report generated with ${report.length} records.`
  });
}
```

## Best Practices

- **Batch operations** - read/write ranges in bulk, never cell-by-cell in loops
- **Cache data** - use CacheService (25 min TTL) for frequently accessed data
- **Error handling** - wrap operations in try/catch, log errors to a sheet for audit trails
- **Respect limits** - 6-minute execution timeout; split large jobs across triggers
- **Minimise scopes** - request only necessary OAuth permissions in `appscript.json`
- **Persistent storage** - use PropertiesService for configuration and state
- **Validate inputs** - always check objects exist before accessing properties

See [references/best-practices.md](references/best-practices.md) for detailed examples of each practice.

## Validation & Testing

Use the validation scripts in `scripts/` for pre-deployment checks:

- **scripts/validators.py** - Validate spreadsheet operations, range notations, and data structures

Debug with `Logger.log()` and view output via View > Logs (Cmd/Ctrl + Enter). Use breakpoints in the Apps Script editor for step-through debugging.

## Integration with Other Skills

- **google-ads-scripts** - Export Google Ads data to Sheets for reporting
- **gtm-datalayer** - Coordinate with GTM for tracking events triggered by Apps Script
- **ga4-bigquery** - Query BigQuery from Apps Script and write results to Sheets

## Troubleshooting

| Issue | Solution |
|-------|----------|
| Execution timeout | Split work into smaller batches or use multiple triggers |
| Authorisation error | Check OAuth scopes in manifest file |
| Quota exceeded | Reduce API call frequency, use caching |
| Null reference error | Validate objects exist before accessing properties |

## References

Detailed content is available in reference files (loaded on demand):

- [references/apps-script-api-reference.md](references/apps-script-api-reference.md) - Complete API reference for all built-in services, triggers, authorisation, and performance optimisation
- [references/examples.md](references/examples.md) - Production-ready code examples (spreadsheet reports, Gmail auto-responder, document generation, trigger setup)
- [references/best-practices.md](references/best-practices.md) - Detailed best practices with code blocks for batch operations, caching, error handling, scopes, and persistence
- [references/patterns.md](references/patterns.md) - Common reusable patterns (data validation, retry logic, form response processing)

Overview

This skill is a comprehensive guide for Google Apps Script development that covers built-in services, triggers, authorization, error handling, and performance optimization. It consolidates practical patterns and ready-to-use techniques for automating Sheets, Docs, Gmail, Drive, Calendar, Forms, and Slides using the V8 JavaScript runtime. Use it to design reliable automations, add-ons, and integrations with external APIs while minimizing quotas and runtime errors.

How this skill works

The skill inspects and documents each core service (SpreadsheetApp, DocumentApp, GmailApp, DriveApp, CalendarApp, FormApp, SlidesApp) and explains triggers, OAuth scopes, and runtime behaviors. It provides code patterns for batch operations, caching, properties storage, UrlFetchApp calls, and retry/error-recovery strategies. It also describes validation, testing workflows, and diagnostics (Logger, breakpoints, audit logging) to make deployments predictable and maintainable.

When to use it

  • Automating Google Sheets tasks: reading, writing, formatting, and custom functions
  • Generating or modifying Google Docs and Slides programmatically
  • Managing Gmail (send, search, label) and Drive files or sharing permissions
  • Automating Calendar events and creating time- or event-based triggers
  • Building Workspace add-ons, handling OAuth scopes, and deployment configuration
  • Calling external APIs with UrlFetchApp and storing transient/persistent data (CacheService, PropertiesService)

Best practices

  • Batch operations: read/write ranges and files in bulk; avoid cell-by-cell loops
  • Use CacheService for short-term caching and PropertiesService for persistent config/state
  • Wrap external calls and critical logic in try/catch and implement retries with exponential backoff
  • Minimize OAuth scopes in appscript.json and request only what you need
  • Respect execution limits (6-minute runtime) by splitting large jobs across triggers or processing in chunks
  • Validate objects and ranges before use to prevent null/reference errors

Example use cases

  • Scheduled weekly report: aggregate Sheet data, write summary, and email stakeholders
  • Drive sync: move and re-share files based on folder rules and metadata
  • Gmail automation: auto-label and respond to specific messages with templated replies
  • Calendar batch updater: create or update recurring events from a data feed
  • Add-on pattern: custom UI + trigger to enrich Sheets with external API data

FAQ

How do I avoid hitting execution timeout?

Split large workloads into smaller batches and use time-based triggers to continue processing between runs.

Where should I store configuration and secrets?

Use PropertiesService for non-sensitive config; store secrets in a secure secret manager if available and restrict scopes. Avoid committing secrets to code.

How can I reduce quota usage when updating Sheets?

Use range reads/writes in bulk, cache repeated lookups, and minimize calls inside loops by transforming data in memory before writing.