0

Alright, my app uses features which require Accessibility, and so I have to bring up the System preferences menu so the user can add our app.

First, I check if Accessibility is enabled. I can do that easily, but I'm having trouble bringing up the systems pane with the Application added to the side panel.

First, I tried using a dictionary along with AXIsProcessTrusted, but to no avail; no dialog showed.

Second, I tried using a trick:

let event = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: true)
event.post(.cghidEventTap)

If our app is not added to Accessibility, then a dialog will pop up, and everything that goes along with it.

Now the important part is that when you press Deny on the dialog, it will still add our app to the Accessibility, but it will NOT be checked.

The issue is that when you do the trick again, and the app is added to Accessibility but is NOT checked, then nothing will happen. No indicators, nothing. That means you don't know if it showed up or not.

Now the third thing i tried is using

NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!)

, which brings up the Accessibility menu.

However, it does not add our app to the side panel.

I've also tried using https://stackoverflow.com/a/18121292/14834900, however, all that does is just bring up the menu, like #3.

Recap

The first method does not work.

The second method brings up the dialog only when our app is not present in Accessibility, but gives no indicator of whether it brought the dialog up or not, which is required because if it did not bring up the dialog, then I would just use method #3, else, I would just continue.

The third method works but does not add our app to the side panel, so the user has to do it himself.

Is there anyway to make the third method add our app to Accessibility, but with it not checked, just like method #2?

The biggest issue I'm facing right now is how to add our app to the Accessbility side panel programmatically, just like the Trick #2

Thanks, I really appreciate it if anybody can lend a hand.

  • 1
    Which Accessibility feature are you talking about? – El Tomato Dec 16 '20 at 06:34
  • Do you mean the Accessibility preference pane or the Accessibility item in the Privacy tab in the Security & Privacy preference pane? – Willeke Dec 16 '20 at 09:32
  • Does this answer your question? [How to ask for Accessibility permission in macOS](https://stackoverflow.com/questions/53616609/how-to-ask-for-accessibility-permission-in-macos) – Willeke Dec 16 '20 at 09:58
  • @Willeke Not quite, as it does not add the application to the Security and Privacy Accessbility side panel. It just brings me there. The user has to press the plus button himself, but using the trick I mentioned, it auto adds the app to it. – testerpersonmana Dec 16 '20 at 16:47

0 Answers0