Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access accessibility settings in MacOSX Cocoa app using swift?

I'm pretty confused. Usually in an iOS app I would access the settings using a url scheme. Now I found out that on MacOSX using Objective-C you can do this:

    NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
    BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);

I've tried to convert this to Swift but didn't got to a valid result. Does anyone know how to convert this or a valid method to ask for assistive access in Swift?

like image 615
eeschimosu Avatar asked Mar 28 '16 08:03

eeschimosu


1 Answers

The kAXTrustedCheckOptionPrompt type is Unmanaged<CFString> so you need to access to the retained value as show below

let options : NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true]
let accessibilityEnabled = AXIsProcessTrustedWithOptions(options)
like image 99
dafi Avatar answered Oct 26 '22 23:10

dafi