12

Does a shell command exist to bring a already started program in gnome in the front of another.

i.e.:

Gedit and Nautilus are started. Nautilus is in the background and Gedit in the foreground.

How to i bring Nautilus in the front with a shell command?

14

Note:

  • More information about xdotool can be found here.
| improve this answer | |
  • Sure edit your post just as I'm composing mine... :( ) – frabjous Jan 12 '11 at 20:58
  • You can find your window name with wmctrl -l The name is the text after the last dash: <window ID> <desktop ID> <client machine> <window title> – jorfus Jul 13 '18 at 22:03
8

Another option is xdotool:

xdotool search --class Nautilus windowactivate

| improve this answer | |
  • 2
    Fails for me with XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1) – Tino Oct 11 '16 at 19:11
  • Probably the bug here -- in my experience --classname or --name (if known) works sometimes when --class doesn't. – frabjous Oct 20 '16 at 19:04
  • In my case it was possible to raise a window using the ID from xwininfo and issuing several additional different xdotool commands (which I no more remember). When I tried to automate that (to get rid of xwininfo) I got visual artifacts due to otherwise hidden windows which were selected, too. I simply found no generic way to address arbitrary windows correctly. After switching to wmctrl -a everything immediately worked flawlessly out of the box without any further tweaking. Please note that I like xdotool, but it seems to be difficult to raise just the correct window with it. – Tino Oct 27 '16 at 10:29
  • xdotool search --desktop 0 Nautilus windowactivate did it for me – Allanrbo May 19 at 7:05
3

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 (here Firefox) 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 the XGetWindowProperty[_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.
| improve this answer | |

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.