Drathier
Drathier

Reputation: 14519

List windows visible on the screen in OSX

Is there a way in OSX to get a list of all applications that are visible on the screen? Can I get a list of all windows of each application, their sizes and position?

Upvotes: 2

Views: 1684

Answers (1)

Frederik.L
Frederik.L

Reputation: 5620

You can achieve that with a tool called wmctrl. It may not be installed on Mac OSX but you can get it with brew install homebrew/x11/wmctrl (first, get brew or any package manager that knows where to find wmctrl if you don't want to mess with git repos and errors).

Then, you should be able to get active windows with something like this:

BASH

wmctrl -l

You may utilize the output of that command into something else afterwards:

BASH

./myProgram $(wmctrl -l)

Hope this helps!


UPDATE:

In case your window manager isn't compatible with wmctrl, your best way out is to use AppleScript for that. There is pretty simple ways of doing it, like suggested in this answer. I think this approach will make it easier for you to get the window attributes.

AppleScript

tell application "System Events"
    repeat with theProcess in processes
        if not background only of theProcess then

[...]

Have fun and good luck :)

Upvotes: 4

Related Questions