Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions BetterCapture/BetterCaptureApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ struct BetterCaptureApp: App {
guard url.scheme == "bettercapture" else { return }

switch url.host {
case "toggle":
case "toggle", "toggle-copy":
let copyToClipboard = url.host == "toggle-copy"
Task { @MainActor in
if viewModel.isRecording {
await viewModel.stopRecording()
await viewModel.stopRecording(copyToClipboard: copyToClipboard)
} else {
switch ContentSelectionMode.current {
case .pickContent:
Expand Down
12 changes: 11 additions & 1 deletion BetterCapture/ViewModel/RecorderViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
}

/// Stops the current recording session
func stopRecording() async {
func stopRecording(copyToClipboard: Bool = false) async {
guard isRecording else { return }

state = .stopping
Expand All @@ -317,6 +317,10 @@
// Send notification
notificationService.sendRecordingSavedNotification(fileURL: outputURL)

if copyToClipboard {
copyFileToClipboard(outputURL)
}

settings.stopAccessingOutputDirectory()

} catch {
Expand Down Expand Up @@ -374,6 +378,12 @@

// MARK: - Helper Methods

private func copyFileToClipboard(_ url: URL) {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.writeObjects([url as NSURL])
}

private func getContentSize(from filter: SCContentFilter) async -> CGSize {
// Apply scale if Capture Native Resolution setting is enabled
let applyScale: Bool = settings.captureNativeResolution
Expand Down Expand Up @@ -498,4 +508,4 @@
captureEngine.clearSelection()
captureEngine.deactivatePicker()
}
}

Check warning on line 511 in BetterCapture/ViewModel/RecorderViewModel.swift

View workflow job for this annotation

GitHub Actions / Lint

File should contain 500 lines or less: currently contains 511 (file_length)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ BetterCapture supports a custom URL scheme for external tools (Raycast, Shortcut
| URL | Action |
|---|---|
| `bettercapture://toggle` | Stop recording if active; otherwise open content selection (Pick Content or Select Area) before recording |
| `bettercapture://toggle-copy` | Same as `toggle`, but copies the saved recording to the clipboard when stopping |
| `bettercapture://open-recordings` | Open the output folder in Finder |

Example:
Expand Down
Loading