Closed ghost closed 7 years ago
$ xdotool search --all --screen 1 --name "^a" | tee /dev/stderr | xargs xdotool getwindowname
14680147
a:2:vim - "vim alfresco.md"
$ xdotool search --all --screen 1 --name "^a:" | tee /dev/stderr | xargs xdotool getwindowname
There are no windows in the stack
Invalid window '%1'
Usage: getwindowname [window=%1]
If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
$ xdotool search --all --screen 1 --name "^b" | tee /dev/stderr | xargs xdotool getwindowname
14680071
b:1:nvim - "vi alfresco.log.2017-06-28"
$ xdotool search --all --screen 1 --name "^b:" | tee /dev/stderr | xargs xdotool getwindowname
14680071
b:1:nvim - "vi alfresco.log.2017-06-28"
For anyone else finding this via Google: xdotool uses case-insensitive POSIX Extended Regular Expressions. The matching happens in xdo_search.c
, where check_window_match
uses compile_re
, which delegates to regcomp
with the REG_EXTENDED
and REG_ICASE
flags.
To resolve this issue, I would suggest explicitly stating in the manpage that extended regular expressions are used, with a pointer to the regex(7) manpage. An option to disable regular expressions and require an exact match would also be convenient, since it’s cumbersome to escape a string to be used in a regular expression in a script.
Thanks for this research, @lucaswerkmeister!
I agree it should be documented. I'll merge a patch if someone provides it before I get a chance to work on it.
An option to disable regular expressions and require an exact match would also be convenient
I agree.
Okay, I created PR #182 for the manpage and separate issue #183 for the proposed feature.
xdotool is wonderful, but it took me a lot of guesswork to determine how to match a window title exactly. Indeed, I fear I am not fully there yet. For what I have, which is as follows, probably picks out the first window that ends with the string in question (namely, 'KeePass'), whereas what I want is to pick out the first window that both ends and starts with that string.
timeout 30s xdotool search --onlyvisible --limit 1 --name KeePass$ windowminimize