Scripts & Reports
Reports
Scripts can generate formatted reports that appear in the output panel of the Scripts page. There are two report types:
- Table reports — structured data grids, exportable as CSV, JSON, Markdown, or Google Doc
- Text reports — rich documents with headings, paragraphs, lists, embedded tables, and inline markdown formatting (links, bold, italic, code), exportable as Markdown or Google Doc
Table Reports
Use the table builder to create data grids with named columns:
let table = report_table_new();
report_table_title(table, "Storage Usage Report");
report_table_column(table, "File Name");
report_table_column_aligned(table, "Size (bytes)", "right");
report_table_column(table, "Type");
let big = files(filter("size:gt:10MB"), sort_order("size desc"), 50);
for f in big {
report_table_add_row(table, [f.name, f.size.to_string(), f.mime_type]);
}
report_set_table(table);
log("Report generated with " + big.len().to_string() + " files");
Table Functions
| Function | Description |
|---|---|
report_table_new() | Create a new table builder (returns a handle) |
report_table_title(handle, title) | Set the table title |
report_table_column(handle, header) | Add a left-aligned column |
report_table_column_aligned(handle, header, align) | Add a column with alignment ("left", "center", "right") |
report_table_add_row(handle, values) | Add a row of values (array of strings) |
report_set_table(handle) | Output the table as a report |
Text Reports
Use the text builder for rich documents with multiple sections:
let doc = report_text_new();
report_text_title(doc, "Drive Audit Report");
report_text_heading(doc, 2, "Summary");
let total = count(filter("is:file"));
let shared_count = count(filter("is_shared:equals:true"));
report_text_key_value(doc, (), [
["Total files", total.to_string()],
["Shared files", shared_count.to_string()],
]);
report_text_heading(doc, 2, "Large Files");
report_text_paragraph(doc, "Files over 50MB that may need attention:");
let table = report_table_new();
report_table_column(table, "Name");
report_table_column_aligned(table, "Size", "right");
let big = files(filter("size:gt:50MB"), sort_order("size desc"), 20);
for f in big {
report_table_add_row(table, [f.name, f.size.to_string()]);
}
report_text_embed_table(doc, table);
report_set_text(doc);
Text Functions
| Function | Description |
|---|---|
report_text_new() | Create a new text builder (returns a handle) |
report_text_title(handle, title) | Set the document title |
report_text_heading(handle, level, text) | Add a heading (level 1–6) |
report_text_paragraph(handle, text) | Add a paragraph |
report_text_bullet_list(handle, items) | Add a bullet list (array of strings) |
report_text_numbered_list(handle, items) | Add a numbered list (array of strings) |
report_text_key_value(handle, title, pairs) | Add a key-value summary table |
report_text_horizontal_rule(handle) | Add a horizontal rule |
report_text_embed_table(handle, table_handle) | Embed a table builder's output |
report_text_md(handle, markdown) | Append raw markdown (for blockquotes, sublists, etc.) |
report_set_text(handle) | Output the text document as a report |
Markdown Formatting
Text report content is markdown. Use these helpers to compose formatted text inside paragraphs and list items:
| Function | Returns | Example |
|---|---|---|
md_bold(text) | **text** | md_bold("important") |
md_italic(text) | *text* | md_italic("note") |
md_code(text) | `text` | md_code("sync --force") |
md_link(title, url) | [title](url) | md_link("Dashboard", "https://example.com") |
Formatted Paragraphs and Lists
let doc = report_text_new();
report_text_title(doc, "Formatted Report");
// Inline formatting in paragraphs
report_text_paragraph(doc, "Found " + md_bold("3 issues") + " that need review.");
report_text_paragraph(doc, "Status: " + md_italic("pending") + " — run " + md_code("sync --force") + " to fix.");
// Links in bullet lists
let items = [];
let my_files = files(filter("size:gt:50MB"), sort_order("size desc"), 3);
for f in my_files {
items.push(md_link(f.name, "https://drive.google.com/file/d/" + f.id) + " (" + md_bold(f.size.to_string() + " bytes") + ")");
}
report_text_heading(doc, 2, "Large Files");
report_text_bullet_list(doc, items);
// Raw markdown for advanced formatting
report_text_md(doc, "> **Note:** Review these files before archiving.\n\n");
report_set_text(doc);
Report Examples
Sharing Summary
let table = report_table_new();
report_table_title(table, "Sharing Summary");
report_table_column(table, "Category");
report_table_column_aligned(table, "Count", "right");
let total = count(filter("is:file"));
let shared_count = count(filter("is_shared:equals:true"));
report_table_add_row(table, ["Total files", total.to_string()]);
report_table_add_row(table, ["Shared files", shared_count.to_string()]);
report_table_add_row(table, ["Private files", (total - shared_count).to_string()]);
report_set_table(table);
Storage by File Type
let table = report_table_new();
report_table_title(table, "Storage by Type");
report_table_column(table, "MIME Type");
report_table_column_aligned(table, "Count", "right");
report_table_column_aligned(table, "Total Size (bytes)", "right");
let types = ["application/pdf", "image/png", "text/plain", "text/csv"];
for t in types {
let matching = files(filter("mime_type:equals:" + t), sort_order("size desc"), 0);
let total_size = 0;
for f in matching {
total_size += f.size;
}
report_table_add_row(table, [t, matching.len().to_string(), total_size.to_string()]);
}
report_set_table(table);
Saving and Exporting
Reports appear in the output panel where you can:
- Copy — copy the report as markdown to clipboard (all report types)
- Save as Markdown — save as a
.mdfile (all report types) - Save as CSV — save as a
.csvfile (table reports only) - Save as Google Doc — create a formatted Google Doc in your Drive (all report types)
Saving to Drive from Scripts
Use report_save_to_drive() to programmatically save a report as a Google Doc:
// Save a table report as a Google Doc
let table = report_table_new();
report_table_title(table, "Audit Results");
report_table_column(table, "File");
report_table_column(table, "Status");
report_table_add_row(table, ["doc.pdf", "OK"]);
let doc_file = report_save_to_drive(table);
// Save with a custom title and then share
let doc_file = report_save_to_drive(table, "Q1 Audit Report");
share(doc_file, "team@example.com", "reader");
// Save to a specific folder
let doc_file = report_save_to_drive(table, #{
title: "Monthly Report",
parent_folder_id: "folder-id-here",
});
The returned DtFile handle can be used with other verbs like share(), move_to(), or add_personal_label().
Tips
- Keep table reports focused — 3-5 columns is ideal for readability
- Use
sort_order()to present data in a meaningful order - Test reports with a small
limitparameter first, then remove the limit for the full run - Use Dry Run mode when your report script also includes mutations
- Use
md_link()to add clickable file links in text reports - Use
report_text_embed_table()to mix structured tables with narrative text - Use
report_save_to_drive()to create a shareable Google Doc from any report
Learn More
- Scripting Overview — Language guide and getting started
- Script Reference — Complete function reference
- Audit Scripts — Sharing and access reports