1

I'm want to get the focused window reference in my Cocoa App and I really don't know how. I've read some articles about Accessability API and others about CGWindow but it still not Clear. I got to be able to determine the position of the current focused window, even though it's not from my application (It would be an iTunes Window or a Finder window).

Undo
  • 25,519
  • 37
  • 106
  • 129
Kyle Oliveira
  • 187
  • 1
  • 12

2 Answers2

1

The first window in [NSApp orderedWindows] should fit your needs.

Fatso
  • 1,278
  • 16
  • 46
  • 1
    That will only return the questioner's own windows, not any other applications' windows. – Peter Hosey Feb 26 '12 at 21:01
  • So How can I get at least the active (focused) window on the system, even though this window don't belong to my application?? I really need a reference of that window. – Kyle Oliveira Feb 29 '12 at 14:37
  • This can get you a bit further : http://stackoverflow.com/questions/311956/getting-a-unique-id-for-a-window-of-another-application, and this too : http://stackoverflow.com/a/373210/840518 – Fatso Feb 29 '12 at 18:36
  • I've managed to get the whole process list by using CGWindowListCopyWindowInfo which gives me a array full of Dictionaries with the process data. However There are so many other process that don't match an application window. How can I retrieve only the focused window reference???? Thank you =D – Kyle Oliveira Mar 04 '12 at 22:48
0

I realize this doesn't quite answer your question, but if you're willing to settle for the current application instead of the currently focused window then you should use the currentApplication method of NSRunningApplication. More here.

pseudosudo
  • 6,270
  • 9
  • 40
  • 53