"Open file read-only" by default

Hello,

I like the option “Open file read-only” (in File > Properties > Security tab). However, for now, I have to manually check it (activate it) each time I create a new LO document.

I have two questions :

  1. Is it possible to activate it automatically (“checked by default”) when I create a new LO document?

  2. Is it possible to run a command line to enable this option for a document?

I’m sure I sometimes forget to activate the option, and I do not want to check in all my documents if the option is activated.

So, I would like to create a batch file and run an algorithm. For example: “For each file in {myFolder}, if LO file then {enable option}”.

Thank you very much for your answer.

Please do not hesitate to ask for clarification if necessary.

Fred

Both can be done.

For question 1, start with an empty Writer document and check “Open file read-only.” Then save this as the default template: File → Templates → Save as Template; check “Set as default template”.

For question 2, add this macro to Module1 via Tools → Macros → Organize Macros → LibreOffice Basic.

Sub SetReadOnly
    oDoc = ThisComponent
    oSettings = oDoc.createInstance("com.sun.star.document.Settings")
    oSettings.LoadReadOnly = True
    oDoc.Store
    oDoc.Close(True)
End Sub

Then run this batch file.

set SOFFICE="%ProgramFiles(x86)%\LibreOffice 5\program\soffice.exe"
for /f "usebackq delims=|" %%f in (`dir /b "*.odt"`) do (
    %SOFFICE% "%%f" "macro:///Standard.Module1.SetReadOnly"
)

Sources:

The first option would start with already read-only new document. Which is almost definitely not what OP wants: probably the intention is that the new document is edited when created, but when it is saved and closed, it’s open for reading next time.

Btw: I had to reopen the template, set the flag and resave it to have it set. It looks like when saving first time, the setting was dropped.

“I had to reopen the template…” Odd; it worked the first time when I tried it. Maybe a version difference, or file permissions? My test used 5.4.3.2 on Windows.