I would like to get the size of the current window from a shell script...
Really not much else to say... I would prefer to use wmctrl.
I would like to get the size of the current window from a shell script...
Really not much else to say... I would prefer to use wmctrl.
Will give you something like:
With this you can
grep
andcut
down on these so you are left with the geometry values (columns 3-6).To quote the man page so you understand exactly what the columns are:
Use
xprop
orxwininfo
. Both come by default, no install necessaryUsage examples:
Both commands turn cursor into square/cross to allow selecting a particular window.
Alternatively, one can specify window on command line in XID form
Other posts where these were used
In particular,
xwininfo
, has been actively used by me for scrips , such as on these AskUbuntu questions:I belive wmctrl does not have any option for finding the active window Id directly.
If someone knows how to do it, I'm interested to know..
That said, here are a couple of scripts which print out the active window's size.
This is: wmctrl + xdotool ...(not using sed).
This is: xwininfo + xdotool + sed
xwininfo
is part ofx11-utils
Shell scripts do not know or care about windows. At best they run in a terminal ( which may or may not be displayed in a window ). If you want to get the width and height of the terminal in characters, use the stty utility.
I found
tput cols
to work quite nicely!Got 3 screens, this output 3 lines with the dimensions: