# Ubuntu – Get Window size in shell

command linewindow

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.

wmctrl -lG


Will give you something like:

oli@bert:~\$ wmctrl -lG
0x0384c0d5 -1 1590 1030 330  170  bert N/A
0x01200023 -1 0    0    3840 1200 bert x-nautilus-desktop
0x01000003 -1 3840 2352 1920 24   bert Bottom Expanded Edge Panel
0x01000028 -1 0    2352 1920 24   bert Bottom Expanded Edge Panel
0x0500003e  0 676  252  1404 1015 bert Chromium
0x02e00021  0 3860 160  1361 1084 bert Liferea
0x02000047  0 6650 940  506  683  bert Social broadcast messages
0x04600004  0 4546 460  1263 833  bert oli@bert: ~


With this you can grep and cut 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:

-l

List the windows being managed by the window manager. One line is output for each window, with the line broken up into space separated columns. The first column always contains the window identity as a hexadecimal integer, and the second column always contains the desktop number (a -1 is used to identify a sticky window). If the -p option is specified the next column will contain the PID for the window as a decimal integer. If the -G option is specified then four integer columns will follow: x-offset, y-offset, width and height. The next column always contains the client machine name. The remainder of the line contains the window title (possibly with multiple spaces in the title).