app.csv - CSV Parsing & Generation API

CSV text parsing, file reading, and generation.

Permission level: L0 (safe, always available)

Methods

app.csv.parse(text, options?)

Parses CSV text.

Parameters:

  • text (string) - CSV text content
  • options (table, optional):
    • delimiter (string) - Delimiter (default ,)
    • header (boolean) - Use the first row as headers (default false)

Returns: array, error

-- Basic parsing (returns a 2D array)
local rows = app.csv.parse("name,age\nAlice,30\nBob,25")
-- {{"name", "age"}, {"Alice", "30"}, {"Bob", "25"}}

-- With headers (returns an array of dictionaries)
local rows = app.csv.parse("name,age\nAlice,30\nBob,25", {header = true})
-- {{name = "Alice", age = "30"}, {name = "Bob", age = "25"}}

-- TSV (tab-separated)
local rows = app.csv.parse(tsv_text, {delimiter = "\t"})

app.csv.parseFile(path, options?)

Reads and parses a CSV file.

Parameters:

  • path (string) - CSV file path
  • options (table, optional) - Same as parse()

Returns: array, error

local data, err = app.csv.parseFile("/path/to/data.csv", {header = true})
if data then
    for _, row in ipairs(data) do
        app.log.info(row.name .. ": " .. row.age)
    end
end

app.csv.generate(rows, options?)

Generates CSV text from data.

Parameters:

  • rows (array) - 2D array
  • options (table, optional):
    • delimiter (string) - Delimiter (default ,)

Returns: string, error

local csv = app.csv.generate({
    {"name", "age", "city"},
    {"Alice", "30", "New York"},
    {"Bob", "25", "London"}
})

app.csv.generateFile(path, rows, options?)

Generates CSV and writes it to a file.

Parameters:

  • path (string) - Output file path
  • rows (array) - 2D array
  • options (table, optional) - Same as generate()

Returns: boolean, error

local ok, err = app.csv.generateFile("/path/to/output.csv", {
    {"name", "score"},
    {"Alice", "95"},
    {"Bob", "87"}
})

Examples

Export file list as CSV

function MyPlugin:handleExportCSV(context)
    local rows = {{"File Name", "Size", "Type"}}

    for _, file in ipairs(context.selectedFiles) do
        local info = app.file.info(file)
        if info then
            table.insert(rows, {
                app.path.basename(file),
                tostring(info.size),
                info.type or ""
            })
        end
    end

    local outPath = app.path.join(context.currentDirectory, "file_list.csv")
    local ok, err = app.csv.generateFile(outPath, rows)
    if ok then
        app.notification.show("Done", "Exported " .. (#rows - 1) .. " records")
        app.finder.reveal(outPath)
    end
end
Developer Documentation
User Guide
Getting Started Script Menus FAQ
Script Development
Development Guide
Plugin Development
Quick Start Development Guide Example Plugins
API Reference
Overview API Query Plugin Info Logging Finder Context Plugin Settings Internationalization
UI & Interaction
Dialog Progress Notification Chooser WebView Status Bar Dock
Files & Paths
File Operations Path Utilities Finder Actions Trash Extended Attributes Metadata File Watcher
Data Formats
JSON Plist CSV XML PDF Image
Text & Encoding
String Regex Date & Time Color Crypto
System
Shell Commands Process Application System Info AppleScript Shortcuts
System Info
Network Power/Battery Screen/Appearance Audio Bluetooth Location
Network
HTTP WebSocket URL
Input & Clipboard
Keyboard Mouse Hotkey Clipboard Window
Storage
SQLite Keychain UserDefaults
Media
OCR QR Code
Utilities
Archive UTI Share Timer Wake Lock Thread