[LibO 5.1.5 on debian 8.5] writer close without asking to save, in need of an AUTOMATIC Incremental saving function

Yesterday, I, by mistake, click on the “cross” button, lost a day worth of work !
I clicked on the cross button by mistake, but usually I don’t care, as LibO has always asked me to save my work.
What wasn’t my surprise, when the window just shut up !
A whole day worth of work was lost. I would NOT have clicked on “do not save”, absolutely not.
The auto-saves functon is put to 15 minutes, but the last “bak” file I could find was from this morning. How can it be ?
I installed an add-on to do incremental save.
But I don’t know how to make it automatic. I never think about saving my work till the end of the day, and I won’t begin, as it’s not my job. I would like my work to be saved by LibO each 15 minutes, with the version name each time a little different, with hour and minutes, in order for them no to erase one another.

Similar question has been asked before.

LibreOffice not autosaving documents


The latter links to this OpenOffice forum post that has a macro you might find usefull.

[Basic] Save a document and create a timestamped copy

Updated attached to v1.2. TimedAutoBackup.odt

v1.2 should now also work for OpenOffice.

Updated to v1.3. TimedAutoBackup.odt

Finds path for soffice on linux using “$(prog)” from “com.sun.star.util.PathSubstitution”.
Thanks to @Karolus for answer to find-install-directory-of-libreoffice-on-linux

@mark_t see your change. Will try in Linux. Also might it not be better if the three subs were placed in three separate text files and attached to you answer. Then you can indicate with note the “last modified” date/note.

Linux won’t work this way. Can’t pass parameter in this manner. Problems with “(” in command. Not sure if there is another way. Can do everything else but parameter. Will try to see if another way. At least script is working.

Modified to put extra quotes to avoid problem with “(”. ““macro:///Standard.Autosave.TimedAutomaticBackup(” & oDoc.URL & “)””"
Tested on windows and in virtual box on linux mint.

Tried on xubuntu 16.04 and it did not work. Even tried commenting out GUI check. Tried on Mint 17.3 and it works to a point. One document open all is OK. Open second document and make a change to second, saves first and nothing for second. First document didn’t even have changes. With shell script a it saved better. Also, this is only for Writer.

Again on Mint. Get different results when starting multiple docs. When up for a time, all seems OK.

Back to xubuntu. Copied macros from Mint and all worked OK. Even multi Writer docs seems OK. Must have had keyed something in wrong. Good work.

Hello. Tested with Calc/Writer - no apparent problems. There is a problem with Base. This is not a supported type (and it shouldn’t be for many reasons) but it still tries to go through the process & clears the isModified flag - big problem. Also causes other problems. The following statement inserted into TriggerAutomaticBackup just after getting oDoc seems to work:

If oDoc.supportsService("com.sun.star.sdb.OfficeDatabaseDocument") Then Exit Sub

Thanks @Ratslinger, added your change to the code block.

@mark_t I have possible change to the triggering of the process. As it is a bit long, please see the attachment at the end of my answer. Thank you.

One more change just tried. Remove two lines from routine - “else” and “AutomaticBackup(oDoc)”. Now if document is opened but no changes, no backup is generated. Also, if user does save, no further backups until another change in the document is detected. This can save generation of many backup copies especially is just reading a document.

@Ratslinger I think if the user makes more changes after the timed save then the modified flag would be set again and the user would be warned if they close the document without saving. I was concerned about the reset of modified flag on timed save as that might misrepresent the saved status of the document to the users master copy. I tried setting the modified status from the macro and hadn’t been able to get that to show the modified state on the save icon, but I’ll try again with your code.

@Ratslinger I would also propose an additional modification to avoid a save every 15 minutes the document is open. That is to still trigger from the modified status, reset the modified status after the timed save and also restart the timer for the next timed save. When the Timed save is due, check the modified status and only restart the timer if it was set prior to the timed save. Intention is that timed saves would only start after a modification and stop after a user save to master document.

@mark_t I was too quick with words in the document. Without the change, if the flag is cleared and no further changes made, the document can be closed without saving to the original location and without warning. With this change, the user will be warned.

Regarding you last comment, see my comment about removing two lines from the code - “else” and “AutomaticBackup(oDoc)”.

@mark_t I have tried your suggestion to still trigger from modifies status. This can create multiple timers for same document. IE: modification, timer started; user save, modification, another timer started. Now two going. This can progress.

Moved most of the post and the code into an attached writer doc as the post was getting too long to view, marked as minor edit to avoid bumping the post. @Ratslinger if you could please retest on Linux as I have made additional changes as noted in the document. Also note the recommendation to trigger from both the “Document loading finished” event and “Document has been saved as” event.

@mark_t tried you new code and again problems with bash statement which I haven’t resolved yet. The code works if I replace sText in StartTimerEvent with original. It performs the same as the code I gave you (minus the two mentioned lines & another Event setting). Don’t know the purpose of all the extra code.

@Ratslinger, Did you modify sLinuxOffice to the correct path for your system? I tried to make StartTimerEvent a general version for use in other timed events.