Skip to content

feat(cli): add bettercapture command-line tool - #238

Merged
jsattler merged 6 commits into
mainfrom
237-add-command-line-interface-for-automation-and-agents
Nov 20, 2026
Merged

jsattler merged 6 commits into
mainfrom
237-add-command-line-interface-for-automation-and-agents

Conversation

@jsattler

@jsattler jsattler commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Closes #237

Summary

Adds a bettercapture command so scripts and AI agents can list capture targets, start and stop recordings without the picker, and get the saved file's path back as JSON.

The running app is the server. The CLI is a thin client that sends one JSON request per connection over a Unix socket. The app keeps owning the Screen Recording permission, so terminals and agents never need it. CLI and menu bar act on the same RecorderViewModel, so either can stop a recording the other started.

bettercapture apps
bettercapture record --app com.apple.Safari --duration 30s --wait --json
bettercapture record --area 0,0,1280,720
bettercapture stop
bettercapture skill show   # usage guide for AI agents

Changes

Remove the App Sandbox (e1c29f2)

  • Only the microphone and camera entitlements remain, which the hardened runtime still needs.
  • Removed SUEnableInstallerLauncherService, which Sparkle only uses for sandboxed apps.
  • SandboxPreferencesMigration copies the container's preferences into ~/Library/Preferences once, at launch. That keeps settings, keyboard shortcuts, Sparkle preferences and the output folder bookmark.

Control server in the app (d68060d)

  • New Settings → Command Line → Allow Command-Line Control, off by default. Without it, any local process could record the screen through BetterCapture's permission.
  • The socket is <per-user temp dir>/<bundle id>.sock, with mode 0600. If another copy of the app is already answering on it, the server leaves it alone.
  • Targets: a display (ID, main or name), a window (ID or title), an app (bundle ID or name), or an area of a display. Each matches the exact ID, then the exact name ignoring case, then part of a name. More than one match is an error that lists the candidates.
  • durationSeconds is handled by the app, so a timed recording stops even if the CLI exits.

CLI tool (305a7cc)

  • New BetterCaptureCLI target, built with swift-argument-parser and embedded at BetterCapture.app/Contents/Helpers/bettercapture.
  • --json on every command. Exit codes: 0 ok, 1 failure, 2 usage, 3 target not found or ambiguous, 4 app unreachable, 5 disabled or permission missing.
  • Launches the app if it isn't running.
  • During record --wait, Ctrl-C stops and saves the recording.
  • The app links ~/.local/bin/bettercapture at every launch, without editing dotfiles. Whichever build launched last owns the link. Settings shows whether the login shell finds the command, and either the PATH line to add or that another file is in the way.
  • skill show prints a guide for AI agents, including the tool's full path as a fallback.
  • Shell completions through --generate-completion-script.

Changes from the issue

  • The socket is in the per-user temp directory rather than Application Support. Only the user can access it, and the path stays well under the 104-byte socket path limit.
  • Positional targets such as --display 2 were dropped, since display IDs are small numbers too.
  • --pick and the per-recording options (--codec, --fps, …) are left for a follow-up. record without a target records the main display.

Testing

  • 180 unit tests pass, including new tests for the migration, target matching and the link installer. SwiftLint reports no new violations.
  • Tested by hand against a debug build: autostart, listings, area recording with --duration and --wait, Ctrl-C during --wait, pause and resume, the disabled state, not-found and ambiguous targets, and invalid arguments.

Still to check on a prerelease build:

  • Archive, export and notarization with the embedded tool
  • Sparkle updates without the installer launcher service
  • Settings and Screen Recording permission survive an upgrade from a sandboxed release
  • ~/.local/bin/bettercapture gets created

After release: add binary "#{appdir}/BetterCapture.app/Contents/Helpers/bettercapture" to the Homebrew cask.

@jsattler jsattler linked an issue Nov 19, 2026 that may be closed by this pull request
Migrate preferences from the sandbox container on first launch so
settings, shortcuts and the output folder survive the switch.

Refs #237
Serve one JSON request per connection on a per-user Unix socket so
the command-line tool can list targets and start, pause, stop and
wait for recordings without the picker. Gated behind a new, off by
default Command Line setting.

Refs #237
Ship the tool in Contents/Helpers, link it into ~/.local/bin on
launch, show in Settings whether the login shell finds it, and add
skill show for agents. Keep a running instance's socket when a second
copy, such as the test host, starts.

Refs #237
Debug builds skipped the ~/.local/bin link, and Settings then told
users to fix a PATH that was already correct. Link in every build and
report a link blocked by another file separately from a missing PATH.

Refs #237
Recordings started in the same second shared a file name, and setting
up the writer deletes an existing file at that URL.
Each command-line recording is now a separate session with an ID,
an optional name and metadata, so several can run at once. stop,
pause, resume, wait and status take an ID or name; stop --all stops
every recording.
@jsattler
jsattler force-pushed the 237-add-command-line-interface-for-automation-and-agents branch from 3833b39 to 649b8f7 Compare November 20, 2026 19:19
@jsattler
jsattler merged commit 740fdfd into main Nov 20, 2026
3 checks passed
@jsattler
jsattler deleted the 237-add-command-line-interface-for-automation-and-agents branch November 20, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add command-line interface for automation and agents

1 participant