Shell command to bring a program window in front of another?
Install wmctrl
wmctrl -a <name>
You can also use xdotool
Note:
- More information about xdotool can be found here.
Another option is xdotool:
xdotool search --class Nautilus windowactivate
When using xdotool
, it seems difficult to bring to front all windows for a given application or class using only one command. I end up having better results by wrapping it in a for
loop at the shell level. Using Bash:
for WINDOW in $(xdotool search --desktop 0 Firefox); do
xdotool windowactivate ${WINDOW}
done
Few remarks:
- By default,
xdotool search
will search the pattern (hereFirefox
) in window name, class, and classname. If you want to restrict your search space, use the relevant--class
,--name
or--classname
options. - The
--desktop 0
option limits the search to the first desktop. This seems to be a workaround to avoid theXGetWindowProperty[_NET_WM_DESKTOP] failed (code=1)
mentioned in some comments. - At the time of this writing, the
xdotool
project is stalled since 2015. It still remains my tool of choice though. For personal reasons, Jordan Sissel (the original author) is not as active as he was, so don't hesitate to contribute to the project.