All projects

Implementation reference · macOS 26

DropSweep

DropSweep is a native macOS 26 menu bar utility that summarizes visible items in Downloads by category and disk usage, then moves the confirmed top-level set to the system Trash.

Problem

File-system work in a compact menu

A Downloads folder can contain regular files, nested folders, hidden entries, and items that change while the app is open. DropSweep needs to summarize that state from a menu bar surface without blocking UI updates, then clear only the reviewed top-level entries through a recoverable system operation.

Implementation scope

From menu refresh to Trash

A MenuBarExtra keeps one MenuViewModel for the menu. When the menu opens, the view model starts a cancellable task and awaits Sweeper.scanDownloadsFolder(). The actor enumerates visible direct children of Downloads, measures files and folders, and returns a snapshot of items, categories, and sizes. After confirmation, the view model passes the stored URLs back to the actor, applies a fresh scan, and reports partial failures.

Interface

One menu, one current scan

The menu shows the total item count and disk usage, followed by non-empty categories. Its destructive action is disabled while a scan or sweep is running. Launch at login, update checks, the About panel, and app termination remain separate menu actions.

Downloads: 24 items · 1.5 GB

Installers3 items · 684 MB

Archives4 items · 412 MB

PDFs3 items · 18 MB

Screenshots8 items · 42 MB

Folders2 items · 296 MB

Other Files4 items · 91 MB

Move Listed Items to Trash

Launch at Login

Check for Updates…

About DropSweep

Quit DropSweep⌘Q

Representative menu state using the categories and actions implemented by the app.

The essential loop

Coordinate a confirmed sweep

MenuViewModel snapshots the URLs from the last scan, asks the Sweeper actor to process them, rescans Downloads, and presents any partial failures. The actor performs the parent-path validation and uses the Trash path by default.

swift
func deleteDownloads() {
    guard canDeleteDownloads else {
        return
    }

    scanTask?.cancel()
    isScanning = true
    isDeleting = true
    let itemsToDelete = deletableItems

    deleteTask = Task {
        defer {
            isScanning = false
            isDeleting = false
        }

        let deleteResult = await sweeper.deleteItemsInDownloads(itemsToDelete)
        let scanResult = await sweeper.scanDownloadsFolder()

        guard !Task.isCancelled else {
            return
        }

        applyScanResult(scanResult)

        if !deleteResult.failures.isEmpty {
            showDeleteDownloadsError(
                deletedCount: deleteResult.deleted,
                failures: deleteResult.failures
            )
        }
    }
}

Implementation notes

Actor-isolated scanning and validated removal

MenuViewModel owns presentation state and starts cancellable scan and sweep tasks. The destructive action remains disabled while either operation is running, while the Sweeper actor isolates file-system work and its mutable size cache from the UI.

scanDownloadsFolder() reads the direct children of Downloads with .skipsHiddenFiles. It categorizes regular files, recursively measures visible folders, ignores other file-system values, and reuses cached sizes only while their resource metadata still matches.

deleteItemsInDownloads(_:) standardizes every candidate URL and verifies that its parent is the Downloads directory. The app uses the method’s default Trash path through FileManager.trashItem, reports partial failures, and rescans afterward.

DropSweepApp presents a MenuBarExtra with no primary window. The target uses LSUIElement, disables App Sandbox for direct Downloads access, registers launch at login through SMAppService, and configures Sparkle with SPUStandardUpdaterController.