Customize the front window itself using the accessibility API

I want to install a specific window from an external application (e.g. textedit) for most of the front.

I can successfully get the link to the application using GetFrontProcess, and check if it is larger in front. If it is not, I can use setFrontProcess to make it focused.

Then I can use the accessibility API to view all the windows under this application. I check that a specific window exists, and if I compare it with the largest application window:

//get the front window of textEditApp and store it in 'currentFrontWindow'
    AXUIElementCopyAttributeValue(textEditApp, kAXFocusedWindowAttribute, (CFTypeRef *)&currentFrontWindow);

If the window that interests me is not in front, I need to install it. I thought I could use the AXUIElement Set AttributeValue for this , but I am not getting any success. Below I tried to do this.

//set the front window of textEditApp to be desiredFrontWindow
AXUIElementSetAttributeValue(textEditApp, kAXFocusedUIElementAttribute, desiredFrontWindow);

I checked that this window exists and the application successfully switched to. But why does this line of code not bring the specified window to the fore?

Thanks.

+5
source share
3 answers

But why does this line of code not bring the specified window to the fore?

Because you were trying to set the read-only attribute.

, . : , .

Cocoa/Mac OS X - " ". (., , NSApplication NSWindow, .) , , , kAXMainAttribute kCFBooleanTrue.

frontmost : kAXFrontmostAttribute kCFBooleanTrue. , .

, .

+8

, , .

:

let currentPid = NSRunningApplication.currentApplication().processIdentifier
if let pid = (the pid of the app in question) where pid != currentPid {
  NSRunningApplication(processIdentifier: pid)?.activateWithOptions(.ActivateIgnoringOtherApps)
}

:

let window = (window AXUIElement)
AXUIElementSetAttributeValue(window, NSAccessibilityMainAttribute, true)
+2

, , Carbon, SetFrontProcessWithOptions, kSetFrontProcessFrontWindowOnly .

+1

All Articles