2

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

Hailwood
  • 4,957

2 Answers2

6

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
CNN.com - 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
3

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)