app.trash - Trash API

Move files to the Trash.

Methods

app.trash.moveToTrash(path)

Move a file or directory to the Trash.

Parameters:

  • path (string|array) - file path or array of paths

Returns:

  • Single file: string, error - path in the Trash
  • Multiple files: array<string>, error - array of Trash paths
-- Move a single file
local trashPath, err = app.trash.moveToTrash("/path/to/file.txt")
if trashPath then
    app.log.info("Moved to: " .. trashPath)
end

-- Move multiple files
local paths, err = app.trash.moveToTrash({
    "/path/to/file1.txt",
    "/path/to/file2.txt"
})

Examples

Safely Delete Selected Files

function MyPlugin:handleTrash(context)
    local count = #context.selectedFiles
    if not app.dialog.confirm("Are you sure you want to move " .. count .. " files to the Trash?") then
        return
    end

    local paths, err = app.trash.moveToTrash(context.selectedFiles)
    if paths then
        app.notification.show("Done", "Moved " .. #paths .. " files to the Trash")
    else
        app.dialog.alert("Error", err or "Operation failed")
    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