Swift4: `AXUIElementCopyAttributeValue()` returns `AXError.cannotComplete`

Viewed 806

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.

0 Answers
Related