I am having trouble getting the title attribute of the focused UI event when a kAXValueChangedNotification is processed. The AXUIElementCopyAttributeValue always returns null and it seems that it should be returning something. Here is the part of code that I am using to get the title:
void ProcessNotification(AXObserverRef observer, AXUIElementRef element, CFStringRef notification, void* refcon)
{
// Get the active instance of the MacAccessibleHandler (the refcon parameter)
MacAccessibleHandler* handler = (MacAccessibleHandler*) refcon;
// Get the application title from the application AXUIElementRef (element)
NSString* sendString = nil;
NSString* name = nil;
// this one works fine
AXUIElementCopyAttributeValue(element, kAXTitleAttribute, (CFTypeRef*) &name);
if (name != nil)
{
// this one works fine
AXUIElementCopyAttributeValue(element, kAXRoleAttribute, (CFTypeRef*) &comp);
}
else
{
AXUIElementRef systemWide = AXUIElementCreateSystemWide();
AXUIElementRef app = nil;
AXUIElementCopyAttributeValue(systemWide, kAXFocusedApplicationAttribute, (CFTypeRef *) &app);
AXUIElementCopyAttributeValue(app, kAXFocusedUIElementAttribute, (CFTypeRef*) &attribute);
if (attribute == nil)
assert (true == false);
AXUIElementCopyAttributeValue(attribute, kAXTitleAttribute, (CFTypeRef*) &val);
if (attribute == nil)
assert (true == false); // always gets to this one
}
if (name == NULL)
name = @"unknown";
// Create xml string using values gathered
sendString = [handler CreateXML: cat: ty: comp: name];
}
[handler SendEventInfo: sendString];
}