On my main machine, I have a Ubuntu desktop open and logged on. I am then also logging in to this machine from a remote computer, using X2go which creates a new X-session. I have a libreoffice file open on the original session. I want to save this file and close it - but from the remote machine! (Both sessions have same user logged in; I can sudo if needed)

I have tried using xdotool search but this fails to find the window. Is there a way to do what I want from this second session? I can see the process with ps -A I can even see the open file with lsof! How can I do a "save-and-close" on it?

  • 2
    You could just kill the process - if you don't have any serious unsaved changes this would be simple. If you do, it should still try to recover the document next time you open it. – Wayne Werner Dec 13 '12 at 17:19
  • That's true @wayne, it would probably autorecover... Thanks for the suggestion. Not sure if I wanted to take that chance though! No way to send keypresses (or any other direct messages)? It sounds so simple. – Sanjay Manohar Dec 13 '12 at 17:54
  • I'm sure there are ways - I'm just not aware of them. Some complicated ones involve installing a simple VNC client and setting DISPLAY=:0 (or whatever display your other account happens to be on) and then launch the server and get to it from the client. But that might be excessive. LibreOffice might have a message protocol - I'm not terribly familiar with it because I use either Google Docs or plain text files in Vim (including LaTex)... – Wayne Werner Dec 13 '12 at 18:00
  • use VNC to get access to the main window from another location – Olivier Dulac Dec 28 '12 at 14:29
  • 1
    xdotool runs on the current session $DISPLAY value. You can ssh any machine or vncserver then run xdotool on it. As example, if you run a vncserver on the port 5901 it uses :1 screen by convention. So, run DISPLAY:1 then start any X program (xeyes for test) and would run under the VNC. Same applies to remote vncservers. SSH into machine then simple run export DISPLAY:1 before you use. – m3nda May 22 '15 at 5:13

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 :-)

  • Thank you for the hint xdotool key "Escape" about names but didn't tried long names :D – m3nda May 22 '15 at 5:07

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.