Cómo convertir un Carbon AXUIElementRef a Cocoa NSWindow

En mi proyecto, puedo obtener la ventana en la que está el mouse y puedo usarAXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue); para hacer que la ventana llegue al nivel superior temporalmente. Así que quiero convertir el elemento a Cocoa NSWindow y luego usarmakeKeyAndOrderFront para hacerlo siempre al frente. Alguien sabe cómo implementar esto.

+ (NSArray *)attributeNamesOfUIElement:(AXUIElementRef)element {
    NSArray *attrNames = nil;
    AXUIElementCopyAttributeNames(element, (const void*)&attrNames);

    AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue);

    // Below lines doesn't work.
    HIObjectRef windowref=AXUIElementGetHIObject(element);
    NSWindow *cocoaWindow = [[NSWindow alloc]initWithWindowRef:windowref];

    return attrNames;
}

Respuestas a la pregunta(0)

Su respuesta a la pregunta