Programmatically determine if “enable access for assistive devices” is checked in Cocoa app

前端 未结 2 638
独厮守ぢ
独厮守ぢ 2021-02-08 11:08

Cocoa apps using the NSAccessibility API require \"enable access for assistive devices\" to be checked in the Universal Access pref pane. I\'ve seen many apps pop a warning if t

2条回答
  •  不知归路
    2021-02-08 11:31

    In OS X 10.9 Mavericks, AXAPIEnabled() has been deprecated.

    AXIsProcessTrustedWithOptions can be used instead:

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

    If you pass in YES for kAXTrustedCheckOptionPrompt, the system will show the user a helpful little dialog with a link to System Preferences:

    "YourApp.app would like to control this computer using accessibility features."

    enter image description here

提交回复
热议问题