[Solved] Terminating an office instance cleanly

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 187
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 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
_savage
Posts: 187
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 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
_savage
Posts: 187
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 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 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: 5055
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.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
Post Reply