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
- SpreadsheetApp - Google Sheets automation (read, write, format, data validation)
- DocumentApp - Google Docs creation and editing
- GmailApp & MailApp - Email operations (send, search, manage labels)
- DriveApp - File and folder management, sharing, permissions
- CalendarApp - Calendar events, recurring appointments, reminders
- Triggers & ScriptApp - Time-based and event-driven automation
Quick Start
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 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 - Complete API reference for all built-in services, triggers, authorisation, and performance optimisation
- references/examples.md - Production-ready code examples (spreadsheet reports, Gmail auto-responder, document generation, trigger setup)
- references/best-practices.md - Detailed best practices with code blocks for batch operations, caching, error handling, scopes, and persistence
- references/patterns.md - Common reusable patterns (data validation, retry logic, form response processing)
1---2name: google-apps-script3description: 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.4---56# Google Apps Script78## Overview910Cloud-based JavaScript platform for automating Google Workspace services. Server-side V8 runtime with automatic OAuth integration across Sheets, Docs, Gmail, Drive, Calendar, and more.1112## When to Use This Skill1314Invoke this skill when:1516- Automating Google Sheets operations (reading, writing, formatting)17- Creating or editing Google Docs programmatically18- Managing Gmail messages and sending emails19- Working with Google Drive files and folders20- Automating Google Calendar events21- Implementing triggers (time-based or event-based)22- Building custom functions for Sheets23- Creating Google Workspace add-ons24- Handling OAuth scopes and authorisation25- Making HTTP requests to external APIs with UrlFetchApp26- Using persistent storage with PropertiesService27- Implementing caching strategies with CacheService28- Optimising performance with batch operations29- Debugging Apps Script code or authorisation issues3031## Core Services32331. **SpreadsheetApp** - Google Sheets automation (read, write, format, data validation)342. **DocumentApp** - Google Docs creation and editing353. **GmailApp & MailApp** - Email operations (send, search, manage labels)364. **DriveApp** - File and folder management, sharing, permissions375. **CalendarApp** - Calendar events, recurring appointments, reminders386. **Triggers & ScriptApp** - Time-based and event-driven automation3940## Quick Start4142```javascript43function generateWeeklyReport() {44 const ss = SpreadsheetApp.getActiveSpreadsheet();45 const sheet = ss.getSheetByName('Data');46 const data = sheet.getRange('A2:D').getValues();4748 const report = data.filter(row => row[0]);49 const summarySheet = ss.getSheetByName('Summary') || ss.insertSheet('Summary');50 summarySheet.clear();51 summarySheet.appendRow(['Name', 'Value', 'Status']);52 report.forEach(row => summarySheet.appendRow([row[0], row[1], row[2]]));5354 MailApp.sendEmail({55 to: Session.getEffectiveUser().getEmail(),56 subject: 'Weekly Report Generated',57 body: `Report generated with ${report.length} records.`58 });59}60```6162## Best Practices6364- **Batch operations** - read/write ranges in bulk, never cell-by-cell in loops65- **Cache data** - use CacheService (25 min TTL) for frequently accessed data66- **Error handling** - wrap operations in try/catch, log errors to a sheet for audit trails67- **Respect limits** - 6-minute execution timeout; split large jobs across triggers68- **Minimise scopes** - request only necessary OAuth permissions in `appscript.json`69- **Persistent storage** - use PropertiesService for configuration and state70- **Validate inputs** - always check objects exist before accessing properties7172See [references/best-practices.md](references/best-practices.md) for detailed examples of each practice.7374## Validation & Testing7576Use the validation scripts in `scripts/` for pre-deployment checks:7778- **scripts/validators.py** - Validate spreadsheet operations, range notations, and data structures7980Debug with `Logger.log()` and view output via View > Logs (Cmd/Ctrl + Enter). Use breakpoints in the Apps Script editor for step-through debugging.8182## Integration with Other Skills8384- **google-ads-scripts** - Export Google Ads data to Sheets for reporting85- **gtm-datalayer** - Coordinate with GTM for tracking events triggered by Apps Script86- **ga4-bigquery** - Query BigQuery from Apps Script and write results to Sheets8788## Troubleshooting8990| Issue | Solution |91|-------|----------|92| Execution timeout | Split work into smaller batches or use multiple triggers |93| Authorisation error | Check OAuth scopes in manifest file |94| Quota exceeded | Reduce API call frequency, use caching |95| Null reference error | Validate objects exist before accessing properties |9697## References9899Detailed content is available in reference files (loaded on demand):100101- [references/apps-script-api-reference.md](references/apps-script-api-reference.md) - Complete API reference for all built-in services, triggers, authorisation, and performance optimisation102- [references/examples.md](references/examples.md) - Production-ready code examples (spreadsheet reports, Gmail auto-responder, document generation, trigger setup)103- [references/best-practices.md](references/best-practices.md) - Detailed best practices with code blocks for batch operations, caching, error handling, scopes, and persistence104- [references/patterns.md](references/patterns.md) - Common reusable patterns (data validation, retry logic, form response processing)