A janela deve ser focada porque senão gedit irá ignorar X eventos enviados por xdotool .
Veja o que seu script deve ser:
#!/bin/bash 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