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.
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
appsscript.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
- google-tagmanager - Coordinate with GTM for tracking events triggered by Apps Script
- google-analytics - Query GA4 BigQuery exports 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, authorisation, error handling, and performance optimisation. 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, optimising 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. Do NOT use for standalone Node.js scripts, Google Cloud Functions, Cloud Run, or any non-Apps-Script JavaScript runtime - those use different APIs and quotas.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## Core Services13141. **SpreadsheetApp** - Google Sheets automation (read, write, format, data validation)152. **DocumentApp** - Google Docs creation and editing163. **GmailApp & MailApp** - Email operations (send, search, manage labels)174. **DriveApp** - File and folder management, sharing, permissions185. **CalendarApp** - Calendar events, recurring appointments, reminders196. **Triggers & ScriptApp** - Time-based and event-driven automation2021## Quick Start2223```javascript24function generateWeeklyReport() {25 const ss = SpreadsheetApp.getActiveSpreadsheet();26 const sheet = ss.getSheetByName('Data');27 const data = sheet.getRange('A2:D').getValues();2829 const report = data.filter(row => row[0]);30 const summarySheet = ss.getSheetByName('Summary') || ss.insertSheet('Summary');31 summarySheet.clear();32 summarySheet.appendRow(['Name', 'Value', 'Status']);33 report.forEach(row => summarySheet.appendRow([row[0], row[1], row[2]]));3435 MailApp.sendEmail({36 to: Session.getEffectiveUser().getEmail(),37 subject: 'Weekly Report Generated',38 body: `Report generated with ${report.length} records.`39 });40}41```4243## Best Practices4445- **Batch operations** - read/write ranges in bulk, never cell-by-cell in loops46- **Cache data** - use CacheService (25 min TTL) for frequently accessed data47- **Error handling** - wrap operations in try/catch, log errors to a sheet for audit trails48- **Respect limits** - 6-minute execution timeout; split large jobs across triggers49- **Minimise scopes** - request only necessary OAuth permissions in `appsscript.json`50- **Persistent storage** - use PropertiesService for configuration and state51- **Validate inputs** - always check objects exist before accessing properties5253See [references/best-practices.md](references/best-practices.md) for detailed examples of each practice.5455## Validation & Testing5657Use the validation scripts in `scripts/` for pre-deployment checks:5859- **scripts/validators.py** - Validate spreadsheet operations, range notations, and data structures6061Debug with `Logger.log()` and view output via View > Logs (Cmd/Ctrl + Enter). Use breakpoints in the Apps Script editor for step-through debugging.6263## Integration with Other Skills6465- **google-ads-scripts** - Export Google Ads data to Sheets for reporting66- **google-tagmanager** - Coordinate with GTM for tracking events triggered by Apps Script67- **google-analytics** - Query GA4 BigQuery exports from Apps Script and write results to Sheets6869## Troubleshooting7071| Issue | Solution |72|-------|----------|73| Execution timeout | Split work into smaller batches or use multiple triggers |74| Authorisation error | Check OAuth scopes in manifest file |75| Quota exceeded | Reduce API call frequency, use caching |76| Null reference error | Validate objects exist before accessing properties |7778## References7980Detailed content is available in reference files (loaded on demand):8182- [references/apps-script-api-reference.md](references/apps-script-api-reference.md) - Complete API reference for all built-in services, triggers, authorisation, and performance optimisation83- [references/examples.md](references/examples.md) - Production-ready code examples (spreadsheet reports, Gmail auto-responder, document generation, trigger setup)84- [references/best-practices.md](references/best-practices.md) - Detailed best practices with code blocks for batch operations, caching, error handling, scopes, and persistence85- [references/patterns.md](references/patterns.md) - Common reusable patterns (data validation, retry logic, form response processing)