Drive ToolboxDrive Toolbox
Scripts & Reports

Drive Toolbox Scripting Guide

Generated: 2026-03-11 20:59:43 UTC

Scripts are used for two reasons: (a) to create custom reports and (b) to automate the many actions you can perform in Drive Toolbox.

Scripts are powerful. Use Dry Run to preview changes before running.

Examples:

  • Select files and delete, move, or change sharing settings
  • Create a report listing everyone you share files with
  • Create a dashboard document that organizes files by Label, and contains a link to each file with that label

Users can utilize an integrated LLM to help write scripts.

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 10 largest files:");
for f in big {
    log("  " + f.name + " (" + f.size.to_string() + " bytes)");
}

Running Scripts

Desktop App: Open the Scripts page from the sidebar. Write or load a script, then click Run. Use the Dry-Run toggle to preview changes safely before executing. You can pass variables to scripts using the Variables panel.

The Reference tab provides a comprehensive and readily-accessible listing of Drive Toolbox-specific scripting language features. More general features of the scripting language we use, Rhai, can be found at https://rhai.rs/book.

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 (actions that would actually change your files) are previewed but NOT executed
  • You get a report showing exactly what would happen

Working with Files

Querying Files

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

// Basic queries
let all_folders = files(filter("is:folder"));
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("recently:modified:7d"));
log("Modified this week: " + n.to_string());

See the Filter docs for details on how to write a filter; or use the LLM or Visual Filter Builder to help write the filter you need.

File Properties

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

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

log(f.name);           // "Q1 Report.xlsx"
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());
log(f.can_delete.to_string());

Helper Functions

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

// Extract IDs or names
let all_ids = ids(my_files);
let all_names = names(my_files);

// Look up a specific file
let specific = get_file("1abc123");

Common Tasks

Organizing with Labels

Personal labels are local to your account and instant:

let label = personal_label("needs-review");

// Find unlabeled files modified recently
let recent = files(filter("recently:modified:3d"));
let count = add_personal_label(recent, label);
log("Labeled " + count.to_string() + " files for review");

// Later, remove the label from completed files
let reviewed = files(filter("label:needs-review AND label:done"));
remove_personal_label(reviewed, personal_label("needs-review"));

Cleaning Up Storage

// Find large old files
let old_big = files(
    filter("size:gt:50MB AND modified_time:before:6mo AND owned_by_me:equals:true"),
    sort_order("size desc")
);

log("Found " + old_big.len().to_string() + " large old files:");
for f in old_big {
    log("  " + f.name + " - " + f.size.to_string() + " bytes");
}

// Delete to trash (can be recovered)
delete(old_big);

Managing Permissions

// Share documents with a team member
let docs = files(filter("name:contains:report AND is:file"));
share(docs, "colleague@company.com", "reader");

// Remove sharing from sensitive files
let sensitive = files(filter("label:confidential AND is_shared:equals:true"));
make_private(sensitive);

// Make documentation public
let public_docs = files(filter("label:public-docs"));
make_public(public_docs);

Moving and Renaming

// Move old files to archive
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");

Workspace Admin

For Google Workspace administrators:

// List all workspace users
let users = workspace_users();
log("Total users: " + users.len().to_string());

// Find suspended accounts
let suspended = workspace_users(#{ suspended: true });
for u in suspended {
    log(u.email + " - " + u.full_name + " (suspended)");
}

// Browse organizational structure
let orgs = workspace_org_units();
for org in orgs {
    log(org["path"] + " - " + org["name"]);
}

Using Variables

Scripts can receive variables from the caller via the args map:

// Access variables
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() };

Error Handling

// Try-catch for error handling
try {
    let f = get_file("invalid-id");
} catch(err) {
    log("Error: " + err.to_string());
}

Building Reports

Scripts can produce structured reports — table reports for data grids, or text reports for rich documents with headings, paragraphs, lists, embedded tables, and inline formatting. Text content supports full markdown including links, bold, italic, code, and inline HTML.

Table Reports

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");

Text Reports with Embedded Tables

For richer documents with headings, paragraphs, and embedded tables:

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);

Markdown Formatting Helpers

Use md_bold(), md_italic(), md_code(), and md_link() to compose formatted text inside paragraphs and list items. Use report_text_md() to insert raw markdown for advanced formatting (blockquotes, sublists, inline HTML).

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);

Reference

Read-Only Verbs

These verbs query data without modifying anything:

FunctionParametersReturnsDescription
filterexpression: StringDtFilterValidates the expression using the core filter parser and returns a DtFilter
sort_orderexpression: StringDtSortOrderValidates the sort expression and returns a DtSortOrder
personal_labelname: StringDtPersonalLabelValidates the label name and returns a DtPersonalLabel
shared_labelname: StringDtSharedLabelValidates the label name and returns a DtSharedLabel
filesfilter: DtFilterArray<DtFile>Return all files matching the filter
filesfilter: DtFilter, sort: DtSortOrderArray<DtFile>Return filtered files in the specified sort order
filesfilter: DtFilter, sort: DtSortOrder, limit: INTArray<DtFile>Return filtered, sorted files up to the limit
countfilter: DtFilterINTReturn the number of matching files
get_filefile_id: StringDtFileReturn the file, or error if not found
all_personal_labels(none)Array<String>Return all personal label names
personal_file_labelsfile_id: StringArray<String>Return personal label names for this file
all_shared_labels(none)Array<String>Return all shared label names
shared_file_labelsfile_id: StringArray<String>Return shared label names for this file
all_personal_info_fields(none)Array<Map>Return all personal info fields as maps with: name, field_type
personal_file_infofile_id: StringArray<Map>Return personal info values as maps with: name, field_type, value
all_shared_info_fields(none)Array<Map>Return all shared info fields as maps with: group, field
shared_file_infofile_id: StringArray<Map>Return shared info values as maps with: group, field, value
workspace_users(none)Array<WsUser>Return all workspace users (up to 1000)
workspace_usersoptions: MapArray<WsUser>Return filtered workspace users
workspace_org_units(none)Array<Map>Return org units as maps with: path, name, parent_path, description
logmessage: String()Appends the message to script output
idsfiles: Array<DtFile>Array<String>Return array of file ID strings
namesfiles: Array<DtFile>Array<String>Return array of file name strings
report_table_new(none)INTCreate a new table builder, returns handle
report_table_titlehandle: INT, title: String()Set table title
report_table_columnhandle: INT, header: String()Add a column with default (left) alignment
report_table_column_alignedhandle: INT, header: String, align: String()Add a column with specified alignment
report_table_add_rowhandle: INT, cells: Array()Add a data row
report_set_tablehandle: INT()Set table as the script's report output
report_text_new(none)INTCreate a new text document builder, returns handle
report_text_titlehandle: INT, title: String()Set document title
report_text_headinghandle: INT, level: INT, text: String()Add heading (level 1-6)
report_text_paragraphhandle: INT, text: String()Add paragraph
report_text_bullet_listhandle: INT, items: Array()Add bullet list
report_text_numbered_listhandle: INT, items: Array()Add numbered list
report_text_horizontal_rulehandle: INT()Add horizontal rule
report_text_mdhandle: INT, markdown: String()Append raw markdown (for blockquotes, sublists, inline HTML, etc.)
md_linktitle: String, url: StringStringReturns title with proper escaping
md_boldtext: StringStringReturns text
md_italictext: StringStringReturns text
md_codetext: StringStringReturns text
report_text_key_valuehandle: INT, title: Dynamic, entries: Array()Add key-value summary (title can be () for no title)
report_text_embed_tabletext_handle: INT, table_handle: INT()Embed a table in the text document
report_set_texthandle: INT()Set text document as the script's report output

Mutation Verbs

These verbs modify data. They require confirmation and are intercepted by dry-run mode:

FunctionParametersReturnsDescription
deletefiles: Array<DtFile>StringMove files to trash. Returns action ID.
deletefile: DtFileStringMove a single file to trash. Returns action ID.
deletefiles: Array<DtFile>, options: MapStringDelete files with options. permanent: true for permanent deletion. shared_file_handling controls behavior for files you don't own (default "skip").
deletefile: DtFile, options: MapStringDelete a single file with options.
downloadfiles: Array<DtFile>, destination: StringStringQueue download of files. Returns action ID.
downloadfile: DtFile, destination: StringStringQueue download of a single file. Returns action ID.
downloadfiles: Array<DtFile>, destination: String, options: MapStringQueue download with options. maintain_structure preserves folder hierarchy (default false). flatten is the inverse of maintain_structure. export_google_docs converts Google Docs to Office formats (default true). overwrite controls file overwrite behavior (default "skip").
downloadfile: DtFile, destination: String, options: MapStringQueue download of a single file with options.
sharefiles: Array<DtFile>, email: String, role: StringStringShare files with the user. Returns action ID.
sharefile: DtFile, email: String, role: StringStringShare a single file with the user. Returns action ID.
unsharefiles: Array<DtFile>, email: StringStringRemove user's access. Returns action ID.
unsharefile: DtFile, email: StringStringRemove user's access from a single file. Returns action ID.
make_publicfiles: Array<DtFile>StringSet public read access. Returns action ID.
make_publicfile: DtFileStringSet public read access on a single file. Returns action ID.
make_privatefiles: Array<DtFile>StringRemove all sharing. Returns action ID.
make_privatefile: DtFileStringRemove all sharing from a single file. Returns action ID.
make_restrictedfiles: Array<DtFile>StringRemove public access. Returns action ID.
make_restrictedfile: DtFileStringRemove public access from a single file. Returns action ID.
move_tofiles: Array<DtFile>, folder_id: StringStringMove files to the folder. Returns action ID.
move_tofile: DtFile, folder_id: StringStringMove a single file to the folder. Returns action ID.
move_tofiles: Array<DtFile>, folder_id: String, options: MapStringMove files with options. flatten: true removes folder hierarchy, placing all files directly in the destination (default false).
move_tofile: DtFile, folder_id: String, options: MapStringMove a single file with options.
renamefile: DtFile, new_name: StringStringRename the file. Returns action ID.
create_folderparent_id: String, name: StringStringCreate a folder. Returns action ID.
add_personal_labelfiles: Array<DtFile>, label: DtPersonalLabelINTAdd personal label. Returns count of files modified.
add_personal_labelfile: DtFile, label: DtPersonalLabelINTAdd personal label to a single file. Returns count of files modified.
remove_personal_labelfiles: Array<DtFile>, label: DtPersonalLabelINTRemove personal label. Returns count of files modified.
remove_personal_labelfile: DtFile, label: DtPersonalLabelINTRemove personal label from a single file. Returns count of files modified.
clear_personal_labelsfiles: Array<DtFile>INTClear all personal labels. Returns count of files modified.
clear_personal_labelsfile: DtFileINTClear all personal labels from a single file. Returns count of files modified.
add_shared_labelfiles: Array<DtFile>, labels: ArrayStringAdd shared labels. Returns action ID.
add_shared_labelfile: DtFile, labels: ArrayStringAdd shared labels to a single file. Returns action ID.
remove_shared_labelfiles: Array<DtFile>, labels: ArrayStringRemove shared labels. Returns action ID.
remove_shared_labelfile: DtFile, labels: ArrayStringRemove shared labels from a single file. Returns action ID.
set_shared_infofiles: Array<DtFile>, group: String, field: String, value: StringStringSet shared info field. Returns action ID.
set_shared_infofile: DtFile, group: String, field: String, value: StringStringSet shared info field on a single file. Returns action ID.
set_personal_infofiles: Array<DtFile>, field: String, type: String, value: String()Set personal info field value on files.
set_personal_infofile: DtFile, field: String, type: String, value: String()Set personal info field value on a single file.
starfiles: Array<DtFile>StringStar files. Returns action ID.
starfile: DtFileStringStar a single file. Returns action ID.
unstarfiles: Array<DtFile>StringUnstar files. Returns action ID.
unstarfile: DtFileStringUnstar a single file. Returns action ID.
set_folder_colorfiles: Array<DtFile>, color: StringStringSet folder color. Returns action ID.
set_folder_colorfile: DtFile, color: StringStringSet folder color on a single folder. Returns action ID.
clear_folder_colorfiles: Array<DtFile>StringClear folder color. Returns action ID.
clear_folder_colorfile: DtFileStringClear folder color on a single folder. Returns action ID.
set_descriptionfile: DtFile, text: StringStringSet file description. Returns action ID.
report_save_to_drivehandle: INTDtFileSave report as Google Doc to Drive root. Uses the report title or a default.
report_save_to_drivehandle: INT, title: StringDtFileSave report as Google Doc with custom title.
report_save_to_drivehandle: INT, options: MapDtFileSave report as Google Doc with options map.
transfer_ownershipfiles: Array<DtFile>, email: StringStringQueue ownership transfer. Returns action ID.
transfer_ownershipfile: DtFile, email: StringStringQueue ownership transfer for a single file. Returns action ID.
accept_transferfiles: Array<DtFile>StringAccept incoming transfers. Returns action ID.
accept_transferfile: DtFileStringAccept incoming transfer for a single file. Returns action ID.
accept_transferfiles: Array<DtFile>, options: MapStringAccept incoming transfers with options. rename_originals: true renames originals in sender's Drive (default false).
accept_transferfile: DtFile, options: MapStringAccept incoming transfer for a single file with options.
reject_transferfiles: Array<DtFile>StringReject incoming transfers. Returns action ID.
reject_transferfile: DtFileStringReject incoming transfer for a single file. Returns action ID.
cancel_transferfiles: Array<DtFile>StringCancel outgoing transfers. Returns action ID.
cancel_transferfile: DtFileStringCancel outgoing transfer for a single file. Returns action ID.

All Types

DtFile

A Google Drive file or folder with read-only properties

PropertyTypeDescription
idStringGoogle Drive file ID
nameStringFile or folder name
mime_typeStringMIME type (empty for folders)
is_folderboolWhether this is a folder
sizeINTFile size in bytes (0 for folders)
effective_sizeINTEffective size including Google Docs counted size
createdStringCreation timestamp (RFC 3339)
modifiedStringLast modified timestamp (RFC 3339)
parent_idStringParent folder ID (empty if root)
owned_by_meboolWhether owned by the current user
shared_with_othersboolWhether shared with others
labelsArray<String>Personal labels assigned to this file
starredboolWhether starred (marked important)
descriptionStringFile description text
can_deleteboolWhether current user can delete
can_shareboolWhether current user can share
can_downloadboolWhether current user can download
can_editboolWhether current user can edit
can_renameboolWhether current user can rename
web_view_linkStringURL to view file in browser
file_extensionStringFile extension (without dot)
folder_colorStringFolder color hex code
md5StringMD5 checksum (files only)
versionINTFile version number

DtFilter

A validated filter expression for querying files Created with filter().

PropertyTypeDescription
expressionStringThe raw filter expression
descriptionStringHuman-readable description of the filter

DtSortOrder

A validated sort expression for ordering query results Created with sort_order().

PropertyTypeDescription
expressionStringThe raw sort expression

DtPersonalLabel

A personal label for local file organization Created with personal_label().

PropertyTypeDescription
nameStringLabel name

DtSharedLabel

A shared label visible to all users with access Created with shared_label().

PropertyTypeDescription
nameStringShared label name

DtPersonalInfoField

A personal info field descriptor

PropertyTypeDescription
nameStringField name
field_typeStringField type

DtSharedInfoField

A shared info field descriptor

PropertyTypeDescription
group_nameStringGroup name
field_nameStringField name within the group

WsUser

A Google Workspace user from the Admin SDK directory

PropertyTypeDescription
emailStringPrimary email address
full_nameStringFull display name
given_nameStringFirst name
family_nameStringLast name
suspendedboolWhether account is suspended
archivedboolWhether account is archived
is_adminboolWhether user is an admin
org_unitStringOrganizational unit path
has_2faboolWhether 2FA is enabled
user_idStringGoogle Workspace user ID