Feat macos (#2)
--------- Co-authored-by: intelligence <intelligence@debian.local> Co-authored-by: jourintown <jourintown@proton.me> Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
1 parent
136bf7cfa3
commit
32e7f32e0a
22 files changed
+1360
-7
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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user