From 14a3652c7482034382f12765767a3d4daad04f26 Mon Sep 17 00:00:00 2001 From: Alex Rodionov Date: Sun, 5 Jan 2020 10:06:14 -0500 Subject: [PATCH] Explicitly ask for accessibility permissions when pasting The default behavior when AppKit asks for access the first time you paste proves to be error-prone when upgrading to newer versions of Maccy. Closes #60 and #70. --- Maccy/Clipboard.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Maccy/Clipboard.swift b/Maccy/Clipboard.swift index fab54523..cf9f952b 100644 --- a/Maccy/Clipboard.swift +++ b/Maccy/Clipboard.swift @@ -41,6 +41,8 @@ class Clipboard { // Based on https://github.com/Clipy/Clipy/blob/develop/Clipy/Sources/Services/PasteService.swift. func paste() { + checkAccessibilityPermissions() + DispatchQueue.main.async { let vCode = UInt16(kVK_ANSI_V) let source = CGEventSource(stateID: .combinedSessionState) @@ -77,4 +79,9 @@ class Clipboard { changeCount = pasteboard.changeCount } + + private func checkAccessibilityPermissions() { + let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue(): true] + AXIsProcessTrustedWithOptions(options) + } }