diff --git a/BetterCapture/BetterCaptureApp.swift b/BetterCapture/BetterCaptureApp.swift index 1d2cc1c..7c8acd2 100644 --- a/BetterCapture/BetterCaptureApp.swift +++ b/BetterCapture/BetterCaptureApp.swift @@ -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: diff --git a/BetterCapture/ViewModel/RecorderViewModel.swift b/BetterCapture/ViewModel/RecorderViewModel.swift index 519553d..10d711d 100644 --- a/BetterCapture/ViewModel/RecorderViewModel.swift +++ b/BetterCapture/ViewModel/RecorderViewModel.swift @@ -290,7 +290,7 @@ final class RecorderViewModel { } /// Stops the current recording session - func stopRecording() async { + func stopRecording(copyToClipboard: Bool = false) async { guard isRecording else { return } state = .stopping @@ -317,6 +317,10 @@ final class RecorderViewModel { // Send notification notificationService.sendRecordingSavedNotification(fileURL: outputURL) + if copyToClipboard { + copyFileToClipboard(outputURL) + } + settings.stopAccessingOutputDirectory() } catch { @@ -374,6 +378,12 @@ final class RecorderViewModel { // 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 diff --git a/README.md b/README.md index d16084f..fb2afff 100644 --- a/README.md +++ b/README.md @@ -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: