BigSur - Querying the bounds of any visible window?
NOTE - More clarification of this question has been added. See "UPDATE", below.
Is there a way in BigSur (version 11.6) to query the dimensionsbounds of any window that is showing on the screen?
When running under X Windows in linux, I can run the xwininfo
command and click on any open window, and the window's attributes, including its dimensionsbounds, will be output. Is there a corresponding command for MacOS? Note that I am not running X Windows on my Mac.
Thank you very much in advance.
UPDATE: I mentioned the following below in the comments, but I want to add it here also now, for clarity ...
There are cases where I don't know the application name of the window whose dimensionsbounds I want to query. All I see is a window, and sometimes, there is no indication on the window itself as to what application the window belongs to. If I do not know the application name of a given window, how can I query the dimensionsbounds of that particular window?
Also, there is another issue: there are some windows which are not created by a normal *.app
type appliction. For example, when I am using the mpv
program to view a video, that application is not an *.app
; rather, it is simply an executable which has been installed by Homebrew. Because of this, there is no way to query its window's bounds using the following Applescript command ...
tell application "mpv"
set position to bounds of window 1
end tell
This Applescript command fails with windows created with non-*.app
type programs such as mpv
.
I am looking for a more general way to query window dimensions, even if I don't know the name of the application controlling the window, and even if the application is not a standard *.app
application.
Is there a way to do this?
Solution 1:
You can use AppleScript to get window information from all processes (no matter if you know the application name, or if it even is an "app" at all):
osascript -e 'tell application "System Events" to get the size of every window of every process'
Note that depending on macOS version, you might need to go to Settings > Security & Privacy and give Accessibility permissions to osascript/Terminal.app.