Command-line way to send keystrokes to a window open on a different X-session

Assuming the default configuration, xdpyinfo on "original" would show a display of ":0.0", e.g.

xdpyinfo | grep name

If your DISPLAY environment variable on "x2go" is ":1.0" then it should be so.

From a terminal on "x2go" Try to find the window-id:

DISPLAY=:0.0 xwininfo -root -tree | grep Writer

It's possible that access control is set up so that it will not work, but I think it should if you are the same userid on the same host (i.e. access to ~/.Xauthority). Check "xauth list" output if no access.

If it works, then use your favourite tool to control it. Add "-int" to the xwininfo above to print the windowid in decimal if your tool requires it that way, xdotool does not:

export DISPLAY=:0.0
xdotool windowactivate 0x15a18918
xdotool windowfocus 0x15a18918
xdotool key "ctrl+s"
xdotool key "ctrl+q"

or you might have better luck with these instead of "ctrl+s"/"ctrl+q"

xdotool key "meta+f" "s"
xdotool key "meta+f" "c"
xdotool key "meta+f" "x"

You might need "alt+" instead of "meta+", I have non-standard meta/alt/super mappings. meta works for me, tested using an Xnest. I'm assuming unaltered English menu layout and accelerators.

It's possible there's a popup in your way, in which case it's worth trying:

xdotool key "Escape"

a few times, then retrying the save & close. Remember xdotool is fussy about exact case of "key" names.

You should be able to try all this by starting libreoffice on x2go, and NOT modifying your DISPLAY. You should save the commands to a shell script file so that focus changes don't mess you up.

lsof should show file no longer open if it worked :-)


It looks like there's a couple of possible requirements. apparently the host needs to be in the xhosts file (it was marked as answer) and the appropriate DISPLAY value exported. This post here should help you do it the way you wanted, allowing xdotool to find remote x11 window.