Reputation: 5283
Is it possible to get a AXUIElementRef of an open application knowing its PID?
My project is opening a file/folder. Then I get its PID and I want to be able to get access to this open window, so that is why I want AXUIElementRef of it.
Upvotes: 1
Views: 607
Reputation: 700
Here is my solution as below in Swift 5
let applicationRef = AXUIElementCreateApplication(pid)
var uiElementsValue: AnyObject?
AXUIElementCopyAttributeValue(applicationRef, kAXWindowsAttribute as CFString, &uiElementsValue)
guard let appElements = uiElementsValue as? [AXUIElement] else { return }
'appElements' are your opening windows.
Upvotes: 0
Reputation: 15598
extern AXUIElementRef AXUIElementCreateApplication ( pid_t pid);
Creates and returns the top-level accessibility object for the application with the specified process ID.
Upvotes: 1