0
votes

I'm trying to move other applications in OSX using the accessibility API. I actually have this working. But I ran into a major issue.

AXUIElementRef appRef = AXUIElementCreateApplication(self.pid);

This uses the PID of my application to to later move the window. I found that multiple windows have the same PID, and when i try and move the second window of application my app crashes.

Can I move my application using just WindowID?

1

1 Answers

0
votes

The way to uniquely identify a particular window if you really need to is by going through the results of CGWindowListCopyWindowInfo to select the ones matching the pid that you're using for appRef there; then the kCGWindowNumber CFNumber is Quartz's unique CGWindowID for that window.

However, sounds more likely that you're just indexing through the windows incorrectly. This should work for your appRef:

CFArrayRef windows;
AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute, (CFTypeRef*)&windows);
int windowCount = windows ? CFArrayGetCount(windows) : 0;
for (int windowIndex = 0; windowIndex < windowCount; windowIndex++)
{
    AXUIElementRef windowRef = (AXUIElementRef)CFArrayGetValueAtIndex(windows, windowIndex);
    ... move windowRef here ...
}

If that doesn't make the problem obvious, post the code which crashes and how it does so.