Skip to content

Instantly share code, notes, and snippets.

@MaartenW
Last active August 22, 2016 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaartenW/fdfd52998ace28e201764a6a02935790 to your computer and use it in GitHub Desktop.
Save MaartenW/fdfd52998ace28e201764a6a02935790 to your computer and use it in GitHub Desktop.
Check if MacOS app has assistive access and request if it hasn't
- (BOOL)assistiveEnabled{
NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @NO};
BOOL aen = AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options);
return aen;
}
- (void)handleAssistiveAccess{
if (![self assistiveEnabled]) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Open preference panel"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Allow assistive access?"];
[alert setInformativeText:@"For Enso to work, you need to tell your Mac that you want to allow Enso to control the display of notifications.\n\nClick the [Open preference pane] button and drag the Enso app into the area with the apps that are allowed to 'control your computer'.\n\nNote: You might first have to unlock the preference pane by clicking the lock at the bottom of the pane.\n\nEnso only changes the display of notifications! You can read more about what enso does at http://enso.magnatron.nl/#privacy"];
if ([alert runModal] == NSAlertFirstButtonReturn) {
alert = nil;
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(dndAvailInabit:) name:@"com.apple.accessibility.api" object:nil];
}else{
alert = nil;
**Do some other stuff
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment