Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As far as I know the below line of code should pull into focus the open nautilus window

xdotool windowactivate `xdotool search --onlyvisible --class nautilus`

But I am getting the error

xdotool: Unknown command: 21043361

share|improve this question
i've done it here… – Possum Gallo Oct 18 '15 at 18:04
up vote 2 down vote accepted

I think what's happening is that the inner xdotool command is reporting multiple window IDs. So the outer command sees something like xdotool windowactivate 12345678 21043361 and doesn't know what to make of the second number.

If you don't mind which open Nautilus window you activate, you can select the first one:

xdotool windowactivate $(xdotool search --onlyvisible --class nautilus | head -n 1)

If you do mind, you might want to select further with --title or --maxdepth.

To exclude the root window, which is provided by Nautilus, this should work:

xdotool windowactivate $(xdotool search --onlyvisible --class nautilus |
                         grep -vxF $(xwininfo -int -size -root |
                                     sed -n 's/.*Window id: *\([0-9]\+\).*/\1/p') |
                         head -n 1)
share|improve this answer
It still gets the same error. – Hailwood Oct 31 '12 at 0:14
You are correct though, it is getting two ID's which is the issue, but your line of code still returns two? – Hailwood Oct 31 '12 at 0:15
@Hailwood Oops, I forgot the option to head to tell it to output only one line. Fixed. – Gilles Oct 31 '12 at 0:16
Adding --limit 1 has the effect you were going for, I shall accept this answer as it helped me find the issue :) – Hailwood Oct 31 '12 at 0:17
Ah nice, now my question is, is there a difference between xdotool windowactivate xdotool search --limit 1 --onlyvisible --class nautilus`` and what you have? – Hailwood Oct 31 '12 at 0:19

xdotool author here.

What you are seeing is very likely that there are two window ids. You could try and figure out exactly which window id was the one you wanted, but in most cases can just use the 'command chaining' and 'window stack' features - see "WINDOW STACK" and "COMMAND CHAINING" in the xdotool manpage.

The simplest solution to your question is to have xdotool search and pass the window ids directly to the windowactivate command, like so:

xdotool search --onlyvisible --class nautilus windowactivate

The above does a search, saves the results on the window stack, then calls windowactivate, which with no arguments applies to the first window on the window stack (aka '%1'). Think of it as a way to pipe search results into other xdotool commands within the same command line.

Here's another example to get the titles of all google chrome windows, using the '%@' window stack thing that means 'all windows on the stack' (unlike %1, %2, etc which are specific windows in the stack)

% xdotool search --onlyvisible --class chrome getwindowname %@   
asdf - Google Search - Google Chrome - Breaking News, U.S., World, Weather, Entertainment & Video News - Google Chrome
Ask Ubuntu - Google Chrome
Google Chrome

In general, any command that emits a window id (search, selectwindow, getactivewindow, etc) will populate the window stack for use with chained commands. Another example, killing a window (usually quits an application) by clicking on it:

% xdotool selectwindow windowkill
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.