1

I am developing an utility for OSX which need to use Universal Access (accessibility and event tap).

I am using AXIsProcessTrustedWithOptions to check if the application is allowed. I am checking this state every second (pooling) in order to detect when user is allowing it.

Unfortunately, AXIsProcessTrustedWithOptions is always returning false, even when the application has been allowed.

I know it is possible because others applications like popclip are doing it but I cannot figure out what I am doing wrong.

Added: code

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:(id)kCFBooleanTrue, kAXTrustedCheckOptionPrompt, nil];
if (!AXIsProcessTrustedWithOptions((CFDictionaryRef)options) ) {
    while (!AXIsProcessTrustedWithOptions(NULL)) {
        NSLog(@"Still not allowed");
        [NSThread sleepForTimeInterval:1.0f];
    }
    NSLog(@"user just allowed the application");
}
else
{
    NSLog(@"App is already allowed");
}
AP.
  • 5,205
  • 7
  • 50
  • 94
  • And if you restart the app? Do you run in Xcode? – Willeke Sep 16 '16 at 22:06
  • I tried both in Xcode (in that case I allow Xcode) or starting the app from the finder. If I restart the app, in that case it works fine but the user experience is not very good :( – AP. Sep 17 '16 at 07:51
  • I tried this (OS X 10.11) and it works. Show us your code. – Willeke Sep 17 '16 at 12:55
  • I've edited the initial question to include the code. Thanks for your help. – AP. Sep 17 '16 at 13:43
  • actually, issue is with [NSThread sleepForTimeInterval:1.0f];..... – AP. Sep 17 '16 at 14:10
  • I used a timer. – Willeke Sep 17 '16 at 21:01
  • I have an issue with this. Sometimes it will show correctly true/false however closing the app out and re-running the app prompts the user for permissions when it is already set. Any idea? – Potion Mar 28 '19 at 05:18
  • In my case `AXUIElementCopyAttributeNames` didn't give any attributes. I solved it by disabling **App Sandbox** in the projects `.entitlements` file. See https://stackoverflow.com/a/50901425/5233188 – goulashsoup Apr 23 '23 at 13:20

0 Answers0