Enable access to assistive device programmatically

I want to enable Access programmatic access for assistive devices in the system settings. But the problem is that my application does not work as a root user, and I do not want my application to be a root user, and also does not have to request any authentication between them.

I want to use all keyboard events around the world. I am using CGEventTapCreate () for the same. The CGEventTapCreate () API documentation mentions that Event taps receive key and key down events if one of the following conditions is true:

  • The current process runs as root.
  • Access to assistive devices enabled. In Mac OS X version 10.4 and later, you can enable this feature using System Preferences, Universal Access panel, Keyboard View.

I tried it manually by installing Enable Access for assistive devices from System Preference, and this gives me the expected result.

So, is there a way to do the same through a program without asking for authentication, and also the application does not work as root?

Thanks,

Dheeraj.

+7
scripting objective-c accessibility cocoa accessibility-api
source share
4 answers

You can run Applescript (or translate Applescript into a ScriptingBridge or something like your Objective-C layer on top of AppleEvents)

Here is the Applescript I'm using in one specific project that does something similar to what you need:

on isUIScriptingOn() tell application "System Events" to set isUIScriptingEnabled to UI elements enabled return isUIScriptingEnabled end isUIScriptingOn on turnUIScriptingOn(switch) tell application "System Events" activate set UI elements enabled to switch end tell end turnUIScriptingOn on run if not isUIScriptingOn() then display dialog "Enable Access for assistive devices (found in the Universal Access System Preference) must be on for this software to correctly work. This program will enable this setting for you" turnUIScriptingOn(true) display dialog "Access for assistive devices in now on" end if end run 
+6
source share

It is good that a solution / some background information can be found at this address .

So, Apple came up with another solution in Tiger that solves these problems: the magic function AXMakeProcessTrusted . This will allow the API only for your application and should be called from a process running as root, so it is safe . It is also all automatic, therefore, without asking the user about his / her password, the user does not need to do anything. The problem is that no one seems to be using it. Each third-party application that I saw, and even Automator, simply asks the user to manually check the System Preferences box. This is a lot of work to implement and has one huge, undocumented error (the application must be rewritten before it is actually checked by Update: indicated as # 5711990), but I really think people should use it. So, I thought I would release the code so that it would be easy to implement it in your application. It includes an auxiliary agent that you can simply add to your project.

+4
source share

It is usually considered rude to change the settings of the user system without saying at least telling them if you are not explicitly asking for permission. Most applications that require this option simply check to see if it is allowed, and if not, let the user know.

+3
source share

There is a way to enable it for each process. Unfortunately, I don’t know what it is, I have applications that do this, and I think I find that I see something about it on the cocoa dev mailing list

Are you sure that it is possible to enable it based on each process, without having to have administrator rights? And if so, will all events or only those related to the process be captured?

0
source share

All Articles