Why does AXUIElementCopyAttributeValue return kAXErrorCannotComplete

I'm experimenting with the Accessibility API and I'm currently trying to interrogate the system wide accessibility element.


According to AXUIElementCopyAttributeNames the system wide element has 4 attributes (AXRole, AXRoleDescription, AXFocusedUIElement & AXFocusedApplication).

I can successfully use the following chunk of code to get the attribute value for the AXRole and AXRoleDescription elements but when I try to get the value of the AXFocusedUIElement or AXFocusedApplication attributes AXUIElementCopyAttributeValue returns kAXErrorCannotComplete.

AXUIElementRef systemWideElement = AXUIElementCreateSystemWide();

CFStringRef attrName = kAXFocusedApplicationAttribute;
CFTypeRef value = NULL;

res = AXUIElementCopyAttributeValue(systemWideElement, attrName, &value);

if (res != kAXErrorSuccess)
    NSLog(@"Failed to get element attribute %@ (%d)", attrName, (int)res);

if (value)
    CFRelease(value);


Does anybody know why AXUIElementCopyAttributeValue is returning kAXErrorCannotComplete / what I'm doing wrong?


Thanks

Because your application is under sandbox.

Remove sandbox from Signing and Capabilities - it should help.

Why does AXUIElementCopyAttributeValue return kAXErrorCannotComplete
 
 
Q