I want libreoffice to exit if there are no documents to recover.
Isn't that superfluous ?
Here's one possible solution. It will only start LibreOffice (LO) if there's actually any document to recover. Otherwise nothing will happen.
LO saves the information needed to restore all open documents in case of a crash in so called "Temporary files". The default location (in linux) is
/tmp and LO saves the data in some directories under
- Change that location to a dedicated directory for temporary files, preferable under
Create new dir:
mkdir -p ~/.cache/lo
Start LO and go to Tools - Options - LibreOffice - Paths
Select Temporary files and click Edit (or double click the entry)
Select (navigate to) the newly created directory:
save, close LO. So from now on LO will place the temporary files (with names like
lu2s2cly.tmp etc) in a directory with a similar name, e.g.
~/.cache/lo. It's only a matter of checking if there's anything to recover and fire up LO.
[ -e ~/.cache/lo/*.tmp ] && libreoffice
save it somewhere in your
/usr/local/bin/odrecover, make it executable.
Then fire up
gnome-session-properties and add
/usr/local/bin/odrecover to your start-up programs. Next time you log in, if there's any document to recover LO will automatically prompt you with document recovery.
sleep 2 in the above script is needed on my system so that LO starts after
gpasted (clipboard manager daemon) otherwise, for some unknown reason,
gpasted goes crazy.