Drive ToolboxDrive Toolbox
Scripts & Reports

Scripts & Reports

Drive Toolbox includes an integrated scripting environment for automating tasks, generating reports, and performing custom operations on your files. Scripts use the Rhai language — a lightweight scripting language designed for embedding in applications.

What Scripts Can Do

  • Query files — use filter expressions to build file lists, count matches, look up specific files
  • Read metadata — access name, size, type, owner, sharing, labels, info fields, and more
  • Modify files — move, rename, star, set folder color, apply labels and info fields
  • Manage sharing — add, remove, or change permissions
  • Generate reports — produce formatted tables and rich text documents with markdown
  • Save to Drive — export reports as Google Docs that you can share
  • Work across accounts — run against multiple connected Google accounts

Getting Started

Your First Script

// Count your files
let total = count(filter("is:file"));
log("You have " + total.to_string() + " files");

// Find large files
let big = files(filter("size:gt:50MB"), sort_order("size desc"), 10);
log("Top " + big.len().to_string() + " largest files:");
for f in big {
    log("  " + f.name + " (" + f.size.to_string() + " bytes)");
}

Running Scripts

Open the Scripts page from the sidebar. Write or load a script, then click Run. Output appears in the right panel.

Dry-Run Mode

Always test scripts with Dry Run first. In dry-run mode:

  • Queries run normally — you see real file counts and names
  • Mutations are previewed but not executed
  • The output shows exactly what would happen

This is the safe way to verify a script before running it for real.

Querying Files

Use filter() to create a search expression and files() to execute it:

// Basic queries
let pdfs = files(filter("name:ends_with:.pdf"));
let big = files(filter("size:gt:10MB"));

// With sorting and limits
let newest = files(filter("is:file"), sort_order("modified_time desc"), 20);
let largest = files(filter("is:file"), sort_order("size desc"), 10);

// Count without loading
let n = count(filter("is:file"));
log("Total files: " + n.to_string());

The filter syntax is the same as the Filter Language Reference.

File Properties

Every file returned by files() is a DtFile object:

let f = files(filter("name:contains:report"))[0];

log(f.name);             // File name
log(f.id);               // Google Drive file ID
log(f.size.to_string()); // Size in bytes
log(f.mime_type);        // MIME type
log(f.is_folder.to_string());
log(f.owned_by_me.to_string());
log(f.starred.to_string());

Helper Functions

let my_files = files(filter("is:file"));

let all_ids = ids(my_files);      // Extract file IDs
let all_names = names(my_files);  // Extract file names
log("Found " + all_names.len().to_string() + " files");

let specific = get_file("1abc123"); // Look up by ID
log("Got: " + specific.name);

Common Tasks

Labels and Metadata

// Apply a personal label to files
let label = personal_label("needs-review");
let targets = files(filter("size:gt:100MB"));
let count = add_personal_label(targets, label);
log("Labeled " + count.to_string() + " files");

// Find files with a specific label
let labeled = files(filter("label:needs-review"));
for f in labeled {
    log(f.name + " has label needs-review");
}

Moving and Renaming

// Move old files to a folder
let archive_id = args["archive_folder"];
let old = files(filter("modified_time:before:1y AND is:file"));
move_to(old, archive_id);

// Create a new folder
create_folder("root-folder", "2026 Archive");

// Rename a specific file
let f = get_file(args["file_id"]);
rename(f, "New Name.docx");

Sharing

// Find shared files
let shared_files = files(filter("is_shared:equals:true"));
log("Shared files: " + shared_files.len().to_string());

// Share files with someone
let reports = files(filter("name:contains:report AND is:file"));
share(reports, "team@example.com", "reader");

// Make sensitive files private
let sensitive = files(filter("label:confidential AND is_shared:equals:true"));
make_private(sensitive);

Variables

You can pass variables to scripts from the Variables panel in the Scripts page. This lets you reuse the same script with different inputs.

// Access variables passed from the UI
let target = args["folder_id"];
let email = args.get("email");  // Returns () if not set

// Use defaults
let limit = if args.get("limit") == () { 100 } else { args["limit"].parse_int() };
log("Target: " + target + ", limit: " + limit.to_string());

Error Handling

Scripts stop on errors by default. Use try/catch for graceful handling:

try {
    let f = get_file("invalid-id");
    log(f.name);
} catch(err) {
    log("Error: " + err.to_string());
}

AI Assistance

The Scripts page includes an integrated AI assistant that can help write scripts. Describe what you want to accomplish and the AI generates a script for you to review, edit, and run.

Learn More