I need assistance in creating a script that does the following:

  1. Open Gedit
  2. Open a document with Gedit
  3. Save the document twice
  4. Close Gedit

I was wondering how can I make it happen with Gedit and xdotool, as xdotool can simulate the key combination to save a document Ctrl+S


The window must be focused because otherwise gedit will ignore X events sent by xdotool.

Here's what your script should be:


gedit -s /path/to/document
# -s is standalone, meaning a new window will be opened instead of a tab in any existing gedit

sleep 5 # wait for gedit to open, adjust if necessary

GEDPID=$!  # save PID of gedit process

sleep 2 # wait for gedit to actually open document, adjust if necessary

GEDWINID=`xdotool search --pid $GEDPID | tail -1`
# gets window ID of gedit, the third "child" is the actual window

xdotool windowactivate --sync $GEDWINID key --clearmodifiers --delay 100 ctrl+s ctrl+s alt+F4
# focus gedit window, wait until focused, then save twice and exit
|improve this answer|||||

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.