I am running Ubuntu GNOME 15.10 with GNOME 3.18 and I am wondering if there is a way from Terminal to close, minimize, unminimize, maximize, and unmaximize specified windows?
Note – I've looked at this Q&A – I am asking how to do it from Terminal… Not how to add the buttons… The buttons are already there, I don't need to add them.
Best Answer
There are two important tools to manipulate windows from
cli
;xdotool
andwmctrl
. Both tools overlap each other in functionality, but the most important commands referring to your question:In an (no doubt incomplete) overview, listing the commands I use most:
Closing a window
wmctrl:
Minimizing a window
xdotool:
Un- minimizing a window
wmctrl:
effectively un- minimizing is done by:
I mention effectively, since the command moves to the corresponding desktop, unminimizes and raises the window, but the command also does that on windows which are not minimized.
Maximizing a window
xdotool:
wmctrl:
Un- maximizing a window:
Notes
Both
xdotool
andwmctrl
are not on your system by default:To run any of the commands on the currently active window:
for
wmctrl
commands, remove the-i
option, replace<window_id>
by:ACTIVE:
for
xdotool
commands: replace<window_id>
by$(xdotool getactivewindow)
In many cases, commands can be run by using either the window id or the window name. The
-i
option inwmctrl
tellswmctrl
to use the window id. I'd suggest not using the window's name as an identifier, to prevent name clashes. It happens more easily then you'd expect.wmctrl
to maximize / unmaximize can be a bit buggy on bothUnity
andGnome
, while thexdotool
option works more robust in my experience. In most scripts, I end up in using a mix of bothwmctrl
andxdotool
.More info on man wmctrl and man xdotool (mainly the section: WINDOW COMMANDS).