Skip to content

Commit

Permalink
Explicitly ask for accessibility permissions when pasting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
p0deje committed Jan 5, 2020
1 parent 7e70276 commit 14a3652
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Maccy/Clipboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -77,4 +79,9 @@ class Clipboard {

changeCount = pasteboard.changeCount
}

private func checkAccessibilityPermissions() {
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue(): true]
AXIsProcessTrustedWithOptions(options)
}
}

0 comments on commit 14a3652

Please sign in to comment.