0

In my project, i can get the window which mouse is on, and i can use AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue); to make the window to top level temporarily. So i want to convert the element to Cocoa NSWindow and then use makeKeyAndOrderFront to make it always in front. Anyone know how to implement this.

+ (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;
}
jimwan
  • 1,086
  • 2
  • 24
  • 39
  • You might be interested in [this post](http://stackoverflow.com/a/6365105/23649). – jtbandes Sep 18 '15 at 02:51
  • One app can't have an `NSWindow*` that refers to the window of another app. Apps can only directly manipulate the windows of their own process. If a given window is the frontmost of its owning app, you can activate that app using `NSRunningApplication` and that will bring the window forward. – Ken Thomases Sep 18 '15 at 03:55
  • Is AXUIElementRef Carbon? – Willeke Sep 18 '15 at 13:26
  • Ah, HIObjectRef is Carbon. – Willeke Sep 18 '15 at 13:38
  • makeKeyAndOrderFront doesn't make a window always in front, it just brings it to the front. What are you trying to do? – Willeke Sep 18 '15 at 13:45

0 Answers0