Mac - List opened windows in terminal
Asked Answered
N

1

9

I want to list opened windows in the terminal to get x, y, width and height like xwininfo -root -tree for X11.

I tried:

osacript -e tell application "Microsoft Word" to get the bounds of the front window

But it's does not work for all Application and you can't specify a child (If you have two Word Document, it return the first opened).

Nelidanelie answered 12/4, 2012 at 13:16 Comment(0)
R
12

To get the position of all windows:

osascript -e 'tell application "System Events" to get the position of every window of every process'

The size:

osascript -e 'tell application "System Events" to get the size of every window of every process'

The title:

osascript -e 'tell application "System Events" to get the title of every window of every process'

Check the reference in AppleScript Editor for more properties.

Regina answered 12/4, 2012 at 13:54 Comment(5)
Thanks but it does not work. When I try : osascript -e 'tell application "System Events" to get the position of every window of every process' I have this error : execution error: System Events got an error: Access for assistive devices is disabled. (-25211)Nelidanelie
go to system preferences -> universal access and enable "Enable access for assistive devices"Regina
Thanks a lot! Last question, how I can determine if the window is in the dock (hidden) or on the front ?Nelidanelie
I found I also had to restart my terminal (iTerm) for permission to be granted (Big Sur)Echopraxia
In Terminal, to print a window title on each line, you can use (without triple quotes): """ osascript -e 'set output to ""' -e 'tell application "System Events"' -e 'repeat with proc in every process' -e 'repeat with w in every window of proc' -e 'set output to output & (name of w) & "\n"' -e 'end repeat' -e 'end repeat' -e 'end tell' -e 'output' """Ferromagnetic

© 2022 - 2024 — McMap. All rights reserved.