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;
}
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 usingNSRunningApplication
and that will bring the window forward. – Hf