I've seen similar questions but not identical ones, how do I resize a specific window to a specific size and location on the screen from within a script? I've seen the use of Resize and Printf but haven't been able to make anything work. Does it matter what type of window it is?

This is in Ubuntu Linux, running a bash script, and the window is opened using gnome. The aim is to manage the size of the GUI window and the position it pops up.

  • 1
    It matters more what desktop environment you are using. How have you tried to use "Resize" (and what is that?) or "Printf" (pritnf? That really isn't relevant here). Please edit your question and give some more details. You are using a GUI, right? – terdon Jun 7 '16 at 15:55
  • 2
    If you've a GUI, use devilspie or wmctrl. – roaima Jun 7 '16 at 16:08
  • You could use the window stack via xwininfo to get the window hex ID, then convert that hex ID to decimal using printf "%i" and then manipulate that window via ID with a keyboard and mouse simulator called xdotool which is absolutely wonderful for simple tasks as this. – Yokai Apr 15 '17 at 9:35

resize (a utility provided with xterm) can resize most xterm-like windows. To get 30 rows by 60 columns, the script would run

resize -s 30 60

to resize the window within which it is running.

In a quick check, mlterm, mrxvt, urxvt, vte (e.g.,. gnome-terminal) and xterm respond to the escape sequence. KDE konsole does not, nor does st or terminology.

Comments mention devilspie and wmctrl, which work with the window manager outside the terminal. The window manager ultimately controls the size and position of every window on an X display, but is a little more complicated to work with, since the script has to determine the window title and use that to tell these programs which window to resize. According to the manual page, devilspie may not be suitable, since it applies to windows as they are created.

Further reading:

| improve this answer | |
  • Hi I tried devilspie but had little luck with it. Tried wmctrl and it worked great first time from command line. However when I put it into my script it won't work at all. Any idea why? this is what i have written: wmctrl -r 'Rarefaction.pdf — R Graphics Output' -e 0,1150,35,740,600 – Giles Jun 9 '16 at 21:48
  • in case anyone views this post and is new to using wmctrl. then the numbers for changing the window size and position relate as follows: 0,left/right,up/down,width,height – Giles Jun 9 '16 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.