Trimmy Specification (draft)
June 11, 2026 · View on GitHub
Purpose
- macOS 15+ menu-bar utility that watches the pasteboard for copied terminal commands and automatically flattens line breaks to make commands pasteable in one go.
- Avoids mangling non-command text via heuristics and user-configurable aggressiveness for general apps and terminals.
Functional Requirements
- Clipboard watcher polls
NSPasteboard.generalvia a GCDDispatchSourceTimer(~150ms, small leeway) to detect ownership changes promptly and rewrites text in-place when it detects shell-like multi-line content. - Detection heuristics score copied text based on:
- Presence of newlines / backslash line continuations
- Pipes/
&&/|tokens - Prompt
$prefixes - "Command-looking" leading tokens (incl. sudo)
- All lines resembling command syntax
- Aggressiveness levels (user setting):
- General apps: None / Low / Normal / High (default: Low).
- Terminals: Low / Normal / High (default: Normal).
- Context-aware trimming applies the terminal level when a terminal app is detected.
- Blank-line handling (checkbox): when enabled, empty lines are preserved during flattening; otherwise all newlines collapse to spaces.
- Auto-trim toggle: enable/disable automatic rewrite without quitting the app; manual "Paste Trimmed" works regardless and does not permanently alter the clipboard.
- Self-write marker: Trimmy writes an extra pasteboard type (
com.steipete.trimmy) so subsequent polls can ignore its own writes and only react to user changes. - Grace delay: small (~80ms) deferred read after detecting a changeCount bump to allow promised/late pasteboard data to become available; skipped if changeCount moves again.
- Robust text read: prefers
readObjects(forClasses:[NSString.self]), falls back to common public text UTI types before declaring “no text”. - UI
- Menu bar icon/text "Trimmy" with menu items: Auto-Trim toggle, "Paste Trimmed", "Paste Reformatted Markdown" (when markdown detected), "Paste Original", status line showing last action preview, Quit.
- General setting: “Show Markdown reformat option” (default on) toggles the menu-only markdown paste action.
- SwiftUI Settings window (macOS-standard Settings scene) organized into General, Trimming, Rules, Shortcuts, Advanced, and About tabs.
- Trimming contains sensitivity pickers for General apps and Terminals plus cleanup behavior.
- Rules contains auto-trim app/site exclusions and URL content-identity parameter rules.
- Last action preview: menu shows truncated (~70 chars) version of last trimmed command.
- Accessory app: no Dock icon, lives in menu bar; quit from menu.
- Accessibility permission UX: when Accessibility is missing, Trimmy blocks paste commands and shows actionable callouts (menu + Settings) to trigger the system prompt and open the Privacy & Security › Accessibility pane.
- CLI helper: Settings → Advanced exposes an installer that symlinks the bundled helper into
/usr/local/binand/opt/homebrew/binastrimmyfor headless use.
Non-Functional Requirements
- Platform: macOS 15.0+; Swift 6; SwiftUI for UI and settings; AppKit for pasteboard access.
- Performance: lightweight polling; avoid excessive CPU; operations on main actor for UI safety.
- Privacy: clipboard data stays local; no network usage.
Build & Run
- Build:
swift build(orswift build -c release). - Run from CLI:
swift run &or execute.build/debug/Trimmy &. - Bundle as .app: run
Scripts/package_app.sh [debug|release]→ outputsTrimmy.appwithLSUIElementset (menu-bar only). Copy to/Applicationsor Drag to Login Items for auto-start. Optional: add an SMLoginItem helper for automatic login launch.
Open Items
- Add packaging script to emit a ready-to-install
.appbundle and optional notarization pipeline. - Optional notification/HUD when a trim occurs.
- Tune heuristics set; consider whitelist for file extensions or URLs.