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
I think what's happening is that the inner xdotool command is reporting multiple window IDs. So the outer command sees something like
If you don't mind which open Nautilus window you activate, you can select the first one:
If you do mind, you might want to select further with
To exclude the root window, which is provided by Nautilus, this should work:
|show 2 more comments|
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:
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)
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: