Accessibility SystemWide object does report the focused application

Originator:markrada26
Number:rdar://10969414 Date Originated:01-Mar-2012 11:50 PM
Status:Open Resolved:
Product:Accessibility Product Version:10.7.3
Classification: Reproducible:Always
 
01-Mar-2012 11:50 PM Mark Rada:
Summary:

Trying to access the currently focused application through the system wide accessibility token does not work.

Steps to Reproduce:

1. Get a reference to the system wide object (AXUIElementCreateSystemWide())
2. Use AXUIElementCopyAttributeValue() to copy the kAXFocusedApplicationAttribute attribute
3. Check the error code returned from AXUIElementCopyAttributeValue()
4. CFShow() the pointer used in the AXUIElementCopyAttributeValue() call

Expected Results:

I expect that I will get an AXUIElementRef object placed in the pointer given to AXUIElementCopyAttributeValue().

Actual Results:

The pointer is never changed and the error code returned by AXUIElementCopyAttributeValue() tells me that there was some kind of error (kAXErrorCannotComplete).

Regression:

I do not know at what point this broke.

Notes:

I have included sample code to show the failure. It first shows that the role for the system wide object can be copied properly, and then it tries the same process to get the focused application but fails.

{{{

#import <Cocoa/Cocoa.h>

int main() {
  AXUIElementRef system = AXUIElementCreateSystemWide();
  CFTypeRef       value = NULL;
  AXError          code = 0;

  code = AXUIElementCopyAttributeValue(system, kAXRoleAttribute, &value);
  NSLog(@"\nAttr: %@\nCode: %i\nValue: %@\n\n", kAXRoleAttribute, code, value);

  code = AXUIElementCopyAttributeValue(system, kAXFocusedApplicationAttribute, &value);
  NSLog(@"\nAttr: %@\nCode: %i\nValue: %@\n\n", kAXFocusedApplicationAttribute, code, value);
}

}}}

Comments

Sandbox?

Mark, is this in a sandboxed app, by chance? If so, check out the bug I filed yesterday:

http://openradar.appspot.com/10961566

(Your code only fails for me in the sandbox. Works fine outside of the sandbox.)

By peter.maurer at March 2, 2012, 11:57 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!