Maximize an application with known PID from CLI

I need to maximize the window of an application when it's minimized using the command line only..

So how to do that knowing the process ID.

When working on the wmctrl command i got the following error:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  20 (X_GetProperty)
  Resource id in failed request:  0x6718
  Serial number of failed request:  11
  Current serial number in output stream:  11

This should work:

xdotool windowactivate `xdotool search --pid YOUR_PID_HERE | tail -1`

xdootool reports a quite a few window id-s when looking up by pid, so I "tailed" the output to only get the last window id from the output. For me it worked well with both Firefox and gnome-calculator. If xdotool only reports one window id for your pid then the tail pipe is of course unnecessary.


You can use wmctrl (man page) to manipulate windows from the command line.

  1. Install the programm using sudo apt-get install wmctrl or any other package manager you feel comfortable with.
  2. Get the window ID belonging to your PID. wmctrl -lp will list all existing windows with their window ID in the first and the PID in the second column of the output.
  3. Raise the window with wmctrl -iR <window ID> or wmctrl -ia <window ID>, depending on whether you want to switch to its desktop or move it to the current one.

This should do it:

awk '$3 == 17213 {print $1}' <(wmctrl -lp) | xargs -i% sh -c "xwit -id % -pop -raise; wmctrl -i -r % -b add,maximized_vert,maximized_horz"

You'll need to change the ID in the awk statement but that will maximise and to activate the window. You'll also need to install xwit (sudo apt-get install xwit) for the un-minimisation to work.


The reason this is so complicated is because no one tool does everything you need and those that are slightly capable, have terminal issues:

  • xdotool can't look up by PID (despite that being an advertised feature)
  • wmctrl doesn't know how to minimise and maximise things
  • xwit can't change window hints but it can un-minimise things

Ideally this is something you should be able to do with just xdotool or wmctrl but their PID look-ups don't work or exist respectively.