Skip to content

Add command-line interface for automation and agents #237

Closed

Description

@jsattler

Summary

Add a bettercapture command-line tool so scripts and AI agents can control BetterCapture: list capture targets, start and stop recordings without the system picker, and get the saved file's path back as JSON.

The running app acts as the server. The CLI is a thin client that sends commands over a Unix socket. The app keeps owning the Screen Recording permission, the active recording, settings, and the recording indicators. Commands from the CLI and from the menu bar act on the same RecorderViewModel.

Commands (v1)

bettercapture status [--json]
bettercapture displays | windows | apps [--json]
bettercapture record [TARGET] [overrides] [--duration 30s] [--wait] [--output PATH] [--json]
    TARGET: --display main|ID|N  --window ID|"title"  --app BUNDLE_ID|name
            --area x,y,w,h [--display …]   --pick
    overrides (this recording only): --codec --fps --container --[no-]mic
            --[no-]system-audio --[no-]cursor
bettercapture stop [--copy] [--json]
bettercapture pause | resume
bettercapture wait [--json]
bettercapture skill show
bettercapture version
  • --json on every command, with stable field names and full IDs.
  • The output path is chosen when recording starts and is returned by record --json.
  • Ctrl-C during record --wait stops and saves the recording.
  • Options passed to record apply to that recording only. They don't change saved settings.
  • Only one recording at a time. record while recording exits 1.
  • Targets are matched by full ID, then name (case-insensitive), then position. An ambiguous match stops without doing anything.
  • If the app isn't running, the CLI launches it and waits for the socket.

Exit codes: 0 ok, 1 failure, 2 bad usage, 3 target not found or ambiguous, 4 app not reachable, 5 permission missing or CLI control disabled, 130 interrupted.

App changes

  • Remove the App Sandbox. Migrate existing settings, including the output folder bookmark, from the container preferences to ~/Library/Preferences on first launch. Drop entitlements that are no longer needed.
  • Socket server at ~/Library/Application Support/BetterCapture/control.sock, with permissions 0600. The protocol is newline-delimited JSON and every message carries a protocol version.
  • "Allow command-line control" setting, off by default. Headless target selection lets any local process use BetterCapture's Screen Recording permission, so the user has to opt in. The usual recording indicators still show.
  • Headless content selection. Build SCContentFilters for displays, windows, apps and areas from SCShareableContent, extending ContentFilterService.

Installation

  • The CLI ships at BetterCapture.app/Contents/Helpers/bettercapture. Contents/MacOS/BetterCapture would clash with it because macOS file names ignore case by default.
  • Homebrew: add a binary line to the cask.
  • DMG: on every launch the app creates or repairs ~/.local/bin/bettercapture. It never overwrites a file that isn't a link into a BetterCapture.app.
  • Settings → Command Line shows whether the command is reachable on the user's login shell PATH. If it isn't, Settings shows the PATH line to add. The app doesn't edit dotfiles.
  • bettercapture skill show prints a guide for agents, including the full-path fallback.

Dependencies

  • swift-argument-parser, linked into the CLI target only.

Out of scope for v1

  • settings get/set
  • events stream

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions