Ubuntu – Is it possible to identify windows using regular expressions in xdotool

command linexdotool

OS: Ubuntu 18.04

Say I have the following five open windows with mozilla in their title:

$ wmctrl -lx
0x03e00018  0 Navigator.Firefox     kububb Ubuntu Manpage: xdotool - command-line X11 automation tool - Mozilla Firefox
0x05a00003  0 leafpad.Leafpad       kububb mozilla1.txt
0x05e00003  0 mousepad.Mousepad     kububb mozilla2.txt - Mousepad
0x06000005  0 kate.kate                N/A mozilla3.txt  — Kate
0x06400093  0 gedit.Gedit           kububb mozilla4.txt (~/Desktop) - gedit

man xdotool has this in the WINDOW COMMANDS section:

search [options] pattern
Search for windows with titles, names, or classes with a regular expression pattern.

and this:

Match against the window name. This is the same string that is displayed in the window titlebar.

Is it possible to exclude only the first entry, the Firefox one?

If I run

xdotool search --name mozilla

five identifiers are listed. How can I list just the four mozilla*.txt ones?

Best Answer

  • Based on a couple of quick tests, it appears to support GNU-style extended regular expressions. Ex. given

    $ wmctrl -ilx | grep brave
    0x04000001  0 brave-browser.Brave-browser  t400s Newest Questions - Ask Ubuntu - Brave
    0x040000fe  0 brave-browser.Brave-browser  t400s file2.txt - Brave
    0x040000ff  0 brave-browser.Brave-browser  t400s fileA.txt - Brave


    $ xdotool search -name 'file.+\.txt'


    $ xdotool search -name 'file[0-9]\.txt'