On Ubuntu desktop, can I use xdotool to mouse click (e.g. click a link) and press some keys (e.g. ctrl+s) on a window (e.g. Firefox's window) that is not in the front, so that I can work on another different window which may need to lie on top of the other windows, while at the same time, let xdotool to work on a hidden window? Thanks.
To get a window id run:
sleep 5; xdotool getactivewindow
This will wait 5 seconds and then get the active window ID. Run this command, click on Firefox, and wait for it to finish. Use that ID in the next step.
You can send keystrokes directly to specific window, by executing:
xdotool type --window [window ID] Hello World
Use the command
man xdotool to get a full list of commands and functions!
Xdotool will generate key events and send them directly to window Firefox. But sending keystrokes to a specific window uses a different API than simply typing to the active window, and many applications just ignore them.
Xdotool can be used to send input to a window that's not in the front. However, not all windows will accept such input. For example,
xterm will not unless you check the "Allow Send Events" options.
Chromium doesn't either. However, Firefox at least as of 2019, does work.
Here is an example which reloads the current tab in all Firefox windows:
xdotool search --class firefox key --window %@ Ctrl+F5
You can automatically activate this window and go back to the previously activated window with : (Exemple with sending Space to Firefox)
xdotool getactivewindow > /tmp/activated_window xdotool windowactivate --sync $(xdotool search --name "Firefox") key space xdotool windowactivate `cat /tmp/activated_window`