How to close, minimize, and maximize a specified window from Terminal?
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.
103 Answers
There are two important tools to manipulate windows from cli; xdotool and wmctrl. 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:
wmctrl -ic <window_id>Minimizing a window
xdotool:
xdotool windowminimize <window_id>Un- minimizing a window
wmctrl:
effectively un- minimizing is done by:
wmctrl -ia <window_id>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:
xdotool windowsize <window_id> 100% 100%wmctrl:
wmctrl -ir <window_id> -b add,maximized_vert,maximized_horzUn- maximizing a window:
wmctrl -ir <window_id> -b remove,maximized_vert,maximized_horzNotes
Both
xdotoolandwmctrlare not on your system by default:sudo apt-get install xdotool wmctrlTo run any of the commands on the currently active window:
for
wmctrlcommands, remove the-ioption, replace<window_id>by:ACTIVE:for
xdotoolcommands: replace<window_id>by$(xdotool getactivewindow)
In many cases, commands can be run by using either the window id or the window name. The
-ioption inwmctrltellswmctrlto 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.- From my own experience, using maximizing in a script;
Using
wmctrlto maximize / unmaximize can be a bit buggy on bothUnityandGnome, while thexdotooloption works more robust in my experience. In most scripts, I end up in using a mix of bothwmctrlandxdotool.
More info on man wmctrl and man xdotool (mainly the section: WINDOW COMMANDS).
4Adding to Jacob Vlijm's answer:
xdotool windowactivate $minwinid
xdotool windowraise $minwinid
xdotool windowfocus $minwinidAlso works for unminimizing a window. The animation is faster for me.
Adding to Jacob Vlijm's answer:
Minimizing a window w/ xdotool by window name:
xdotool search -name '<window_name>' windowminimizeTo get list of windows names use:
wmctrl -l