6

On running the following code:

let pid = getAppPid()
let AXApp = AXUIElementCreateApplication(pid)

var children: CFTypeRef?
let returnVal = AXUIElementCopyAttributeValue(AXApp,
    kAXChildrenAttribute as CFString, &children)
  • AXApp gets created successfully

However

  • children is nil
  • returnVal is AXError.cannotComplete ("A fundamental error has occurred, such as a failure to allocate memory during processing.")

I've seen code on stack overflow and elsewhere using exactly the same method as I am.

What am I missing.

I am using Xcode 9/Swift 4 on MacOS High Sierra.

EDIT:

I should add that Xcode has accessibility permissions, and I am able to successfully do other stuff that requires accessibility permission like CGEvent.tapCreate() to monitor global keyboard events etc.

Anshuman Sharma
  • 417
  • 2
  • 11
  • 1
    Switch off sandboxing. [How to use Accessibility with sandboxed app?](https://stackoverflow.com/questions/32116095/how-to-use-accessibility-with-sandboxed-app) – Willeke Nov 11 '17 at 02:35
  • Thanks, that works. If you add that as answer, I'll mark it as the right one. – Anshuman Sharma Nov 12 '17 at 10:47
  • Also: I was able to get it working by setting the `App Sandbox` key to `NO` in the `.entitlements` file. I this the best way? I couldn't find a key to just request entitlement for accessibility, while preserving the rest of the sandbox compliance features. Do you know if some thing like that exists? Thanks. – Anshuman Sharma Nov 12 '17 at 10:57
  • I don't know anything about App Sandbox. I managed to switch it off but that's it. – Willeke Nov 12 '17 at 14:06
  • cool, I am doing the same. do you want to put your initial comment as an answer? – Anshuman Sharma Nov 13 '17 at 10:52

0 Answers0