$npx -y skills add henkisdabro/wookstar-claude-plugins --skill google-apps-scriptComprehensive 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 opera
| 1 | # Google Apps Script |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | ## Core Services |
| 8 | |
| 9 | 1. **SpreadsheetApp** - Google Sheets automation (read, write, format, data validation) |
| 10 | 2. **DocumentApp** - Google Docs creation and editing |
| 11 | 3. **GmailApp & MailApp** - Email operations (send, search, manage labels) |
| 12 | 4. **DriveApp** - File and folder management, sharing, permissions |
| 13 | 5. **CalendarApp** - Calendar events, recurring appointments, reminders |
| 14 | 6. **Triggers & ScriptApp** - Time-based and event-driven automation |
| 15 | |
| 16 | ## Quick Start |
| 17 | |
| 18 | ```javascript |
| 19 | function generateWeeklyReport() { |
| 20 | const ss = SpreadsheetApp.getActiveSpreadsheet(); |
| 21 | const sheet = ss.getSheetByName('Data'); |
| 22 | const data = sheet.getRange('A2:D').getValues(); |
| 23 | |
| 24 | const report = data.filter(row => row[0]); |
| 25 | const summarySheet = ss.getSheetByName('Summary') || ss.insertSheet('Summary'); |
| 26 | summarySheet.clear(); |
| 27 | summarySheet.appendRow(['Name', 'Value', 'Status']); |
| 28 | report.forEach(row => summarySheet.appendRow([row[0], row[1], row[2]])); |
| 29 | |
| 30 | MailApp.sendEmail({ |
| 31 | to: Session.getEffectiveUser().getEmail(), |
| 32 | subject: 'Weekly Report Generated', |
| 33 | body: `Report generated with ${report.length} records.` |
| 34 | }); |
| 35 | } |
| 36 | ``` |
| 37 | |
| 38 | ## Best Practices |
| 39 | |
| 40 | - **Batch operations** - read/write ranges in bulk, never cell-by-cell in loops |
| 41 | - **Cache data** - use CacheService (25 min TTL) for frequently accessed data |
| 42 | - **Error handling** - wrap operations in try/catch, log errors to a sheet for audit trails |
| 43 | - **Respect limits** - 6-minute execution timeout; split large jobs across triggers |
| 44 | - **Minimise scopes** - request only necessary OAuth permissions in `appsscript.json` |
| 45 | - **Persistent storage** - use PropertiesService for configuration and state |
| 46 | - **Validate inputs** - always check objects exist before accessing properties |
| 47 | |
| 48 | See [references/best-practices.md](references/best-practices.md) for detailed examples of each practice. |
| 49 | |
| 50 | ## Validation & Testing |
| 51 | |
| 52 | Use the validation scripts in `scripts/` for pre-deployment checks: |
| 53 | |
| 54 | - **scripts/validators.py** - Validate spreadsheet operations, range notations, and data structures |
| 55 | |
| 56 | Debug with `Logger.log()` and view output via View > Logs (Cmd/Ctrl + Enter). Use breakpoints in the Apps Script editor for step-through debugging. |
| 57 | |
| 58 | ## Integration with Other Skills |
| 59 | |
| 60 | - **google-ads-scripts** - Export Google Ads data to Sheets for reporting |
| 61 | - **google-tagmanager** - Coordinate with GTM for tracking events triggered by Apps Script |
| 62 | - **google-analytics** - Query GA4 BigQuery exports from Apps Script and write results to Sheets |
| 63 | |
| 64 | ## Troubleshooting |
| 65 | |
| 66 | | Issue | Solution | |
| 67 | |-------|----------| |
| 68 | | Execution timeout | Split work into smaller batches or use multiple triggers | |
| 69 | | Authorisation error | Check OAuth scopes in manifest file | |
| 70 | | Quota exceeded | Reduce API call frequency, use caching | |
| 71 | | Null reference error | Validate objects exist before accessing properties | |
| 72 | |
| 73 | ## References |
| 74 | |
| 75 | Detailed content is available in reference files (loaded on demand): |
| 76 | |
| 77 | - [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 |
| 78 | - [references/examples.md](references/examples.md) - Production-ready code examples (spreadsheet reports, Gmail auto-responder, document generation, trigger setup) |
| 79 | - [references/best-practices.md](references/best-practices.md) - Detailed best practices with code blocks for batch operations, caching, error handling, scopes, and persistence |
| 80 | - [references/patterns.md](references/patterns.md) - Common reusable patterns (data validation, retry logic, form response processing) |