-1

In Ubuntu 20.04, I am trying to write a very small script to bring a specified window to the foreground and then send a key combination on this window.

For that I am using:

#!/bin/bash

xdotool search --onlyvisible --class <myWindow> windowactivate %@

xdotool key ctrl+alt+p

Now, while the specified window in <myWindow> is indeed coming to the foreground, the key combination seems to not have any effect, no error showed or anything like that. However, it does have the desired effect if I send the combination manually with the keyboard and with the window in the foreground.

I also tried adding a little delay sleep 2 between the 2 commands, no luck so far.

Missing something here?

codeKiller
  • 5,493
  • 17
  • 60
  • 115

1 Answers1

0

except windowactivate
maybe also windowfocus
and little sleep ?

xdotool search  --onlyvisible --all  terminator \
 windowactivate windowfocus sleep 0.5 type 'abc'

maybe also --sync

xdotool search  --onlyvisible --class  terminator \
 windowactivate --sync  windowfocus --sync key ctrl+r

man xdotool

windowfocus [options] [window]

Focus a window.
Uses XSetInputFocus which may be ignored by some window managers or programs.

--sync After sending the window focus request, wait until the window is actually focused.

windowactivate [options] [window]

Activate the window.
This command is different from windowfocus: if the window is on another desktop, we will switch to that desktop. It also uses a different method for bringing the window up.
I recommend trying this command before using windowfocus, as it will work on more window managers.

--sync After sending the window activation, wait until the window is actually activated.

yurenchen
  • 1,897
  • 19
  • 17