openstenoproject/plover

Should provide option to go to system preferences when no assistive devices

Opened this issue · 1 comments

Plover says when it needs access to assistive devices, but doesn't offer the user any help.

Note: assistive devices is only needed when the user is using KeyboardCapture with the keyboard machine. Therefore, it is not necessary for all users to enable assistive devices.

We have two options to fix this and make the user's experience a little better:

  1. Use the built-in methods to request assistive devices.

With something like this: source

diff --git a/plover/oslayer/osxkeyboardcontrol.py b/plover/oslayer/osxkeyboardcontrol.py
index 22f6061..3fd2881 100644
--- a/plover/oslayer/osxkeyboardcontrol.py
+++ b/plover/oslayer/osxkeyboardcontrol.py
@@ -44,6 +44,13 @@ from Quartz import (
     NSEvent,
     NSSystemDefined,
 )
+import objc
+
+CoreServicesBundle = objc.loadBundle(
+    'CoreServices', globals(), '/System/Library/Frameworks/ApplicationServices.framework')
+objc.loadBundleFunctions(CoreServicesBundle, globals(), [('AXIsProcessTrustedWithOptions', b'Z@')])
+objc.loadBundleVariables(CoreServicesBundle, globals(), [('kAXTrustedCheckOptionPrompt', b'@')])
+

 from plover.misc import characters
 from plover.oslayer.osxkeyboardlayout import KeyboardLayout
@@ -166,6 +173,7 @@ class KeyboardCapture(threading.Thread):
     _KEYBOARD_EVENTS = set([kCGEventKeyDown, kCGEventKeyUp])

     def __init__(self):
+        AXIsProcessTrustedWithOptions({kAXTrustedCheckOptionPrompt: True})
         threading.Thread.__init__(self, name="KeyboardEventTapThread")
         self._loop = None
         self._event_queue = Queue()  # Drained by event handler thread.

You'd get something like:

screen shot 2017-02-24 at 10 41 42 pm

Pros: UI-agnostic, easy, Apple-sanctioned

  1. Alternatively, we could just use our existing exception and show a custom message at this point. We can then inform the user:

Plover needs Assistive Devices permissions in order to use your keyboard as a steno machine. Please enable assistive devices using the System Preferences, or select another machine type.

[ Cancel ] [ Open System Preferences ]

Then, we can use an AppleScript through a call to osascript:

tell application "System Preferences"
    set securityPane to pane id "com.apple.preference.security"
    tell securityPane to reveal anchor "Privacy_Accessibility"
    activate
end tell

Pros: we can communicate what needs to happen to the user better, but now the implementation is in the UI.

Option 1 seems simple enough, why don't we do that?