[Solved] Terminating an office instance cleanly

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

[Solved] Terminating an office instance cleanly

Post by _savage »

I've created a new office instance:

Code: Select all

soffice --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
and then connected to it do do some work:

Code: Select all

local = uno.getComponentContext()                                       
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
document = desktop.loadComponentFromURL("file:///path/to/file.odt", "_blank", 0, ())
Now my question is: How do I shut down the whole process cleanly, so that I won't get the "Document recovery" dialog next time around I open office. For now I have something like this:

Code: Select all

document.dispose()
desktop.terminate()
# context.??                                                          
# resolver.??                                                         
# local.??                                                            
os.kill(pid, signal.SIGTERM)
Last edited by Hagar Delest on Thu Feb 26, 2015 11:21 pm, edited 1 time in total.
Reason: tagged [Solved].
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Re: Terminating an office instance cleanly

Post by _savage »

Some supporting documentation is here and here.

At the moment I've changed the code to the following:

Code: Select all

if document.supportsService("com.sun.star.util.XCloseable") :
    document.close(True)
document.dispose()
Last edited by _savage on Thu Feb 26, 2015 6:23 pm, edited 1 time in total.
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Re: Terminating an office instance cleanly

Post by _savage »

This question has developed into an interesting thread on the LibreOffice mailing list overe here. I'm going to close this question here, and refer the interested reader to that thread :super:
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
NomNomistan
Posts: 5
Joined: Mon Jun 21, 2021 12:41 pm

Re: [Solved] Terminating an office instance cleanly

Post by NomNomistan »

Link doesnt work anymore
LibreOffice 7.0.3.1 (x64) on Windows 10 20H2
User avatar
robleyd
Moderator
Posts: 5383
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Terminating an office instance cleanly

Post by robleyd »

Unfortunately that is the way of the internet. A few moments work with a search engine led me to https://listarchives.libreoffice.org/ from whence you might be able to find something relevant.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 25.2.31.2; SlackBuild for 25.2.3 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue]
Unexpected '{' on line 32
.
Post Reply