4

I've got an app (made with ElectronJS) that relies on having Accessibility permission to listen for mouse/keyboard events (via the iohook package). I'd like to put it on the Mac App Store, but it appears that:

  1. Mac App Store requires Sandboxing and
  2. Sandboxing does not allow Accessibility permission.

Therefore an app in the Mac App Store cannot get Accessibility permission. Is this right or am I missing something?

mahal tertin
  • 3,239
  • 24
  • 41
sr3
  • 389
  • 2
  • 4
  • 15

1 Answers1

2

You need to use AXIsProcessTrustedWithOptions to request access to Accessibility Permissions.

Here is the full doc from Apple: https://developer.apple.com/documentation/applicationservices/1459186-axisprocesstrustedwithoptions

Example:

let promptFlag = kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString
let myDict: CFDictionary = NSDictionary(dictionary: [promptFlag: true])
AXIsProcessTrustedWithOptions(myDict)

if (AXIsProcessTrustedWithOptions(myDict))
{
    //we have permission granted here
}
Matthew Cawley
  • 2,828
  • 1
  • 31
  • 42
  • 2
    Will this work in an app on the Mac App Store (i.e. sandboxed), or will it just work unsandboxed? I have no issue getting the app to prompt for accessibility permission in development or in production for independent distribution, but when the app is sandboxed for the Mac App Store, it doesn't show the prompt and the system Console app tells me I don't have permission to ask for permission... Is there an entitlement I need to use to be able to ask for accessibility permission, or has Apple just decided that sandboxed apps can't have that level of control (i.e. full mouse/window control)? – sr3 May 27 '20 at 00:31
  • You can disable app sandboxing on your app or alternatively you will want to look at the hardware layer of entitlements: https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW11 Your primary focus here will most likely be the entitlement key: com.apple.security.device.usb – Matthew Cawley May 27 '20 at 13:48
  • Unfortunately, if those entitlements don't give you enough control over the devices, you will have to look at external distribution. – Matthew Cawley May 27 '20 at 13:53