feat:mac os

This commit is contained in:
intelligence committed 2026-08-29 19:58:33 +02:00
1 parent 136bf7cfa3
commit 3400e2b465
18 files changed
+1129

No files matched your search

@@ -0,0 +1,43 @@
import AppKit
import ApplicationServices
import Carbon.HIToolbox
enum OutputResult {
case typed
case copied
case copiedBecauseAccessibilityIsOff
}
enum TranscriptOutput {
@MainActor
static func deliver(_ text: String, to destination: TranscriptDestination) -> OutputResult {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(text, forType: .string)
guard destination == .cursor else { return .copied }
let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true]
guard AXIsProcessTrustedWithOptions(options as CFDictionary) else {
return .copiedBecauseAccessibilityIsOff
}
guard let source = CGEventSource(stateID: .hidSystemState),
let keyDown = CGEvent(
keyboardEventSource: source,
virtualKey: CGKeyCode(kVK_ANSI_V),
keyDown: true
),
let keyUp = CGEvent(
keyboardEventSource: source,
virtualKey: CGKeyCode(kVK_ANSI_V),
keyDown: false
)
else {
return .copiedBecauseAccessibilityIsOff
}
keyDown.flags = .maskCommand
keyUp.flags = .maskCommand
keyDown.post(tap: .cghidEventTap)
keyUp.post(tap: .cghidEventTap)
return .typed
}
}