Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I solved this by writing a simple python uno script which communicates with the libreoffice process and closes all documents. This will remove the lock files: import uno

Connect to LibreOffice

localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager

Create new XDesktop instance

desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

Load all documents Components

componentsEnumerator = desktop.getComponents().createEnumeration()

Default value if any component isn't able to close

closeDenied = False

Iterate through all Components

while componentsEnumerator.hasMoreElements(): # Load document document = componentsEnumerator.nextElement()

# Is close supported?
if not hasattr(document, "close"):
    continue

# Try to close it regulary
try:
    document.close(True)   
except:
    # Dispose the frame of this component
    document.getCurrentController().getFrame().dispose()

ctx.ServiceManager

I solved this by writing a simple python uno script which communicates with the libreoffice process and closes all documents. This will remove the lock files: import unofiles:

import uno

# Connect to LibreOffice

LibreOffice localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager

ctx.ServiceManager

# Create new XDesktop instance

instance desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

ctx)

# Load all documents Components

Components componentsEnumerator = desktop.getComponents().createEnumeration()

desktop.getComponents().createEnumeration()

# Default value if any component isn't able to close

close closeDenied = False

False

# Iterate through all Components

Components while componentsEnumerator.hasMoreElements(): # Load document document = componentsEnumerator.nextElement()

componentsEnumerator.nextElement()
 # Is close supported?
 if not hasattr(document, "close"):
     continue

 # Try to close it regulary
 try:
     document.close(True)   
 except:
     # Dispose the frame of this component
     document.getCurrentController().getFrame().dispose()

ctx.ServiceManager

ctx.ServiceManager

I solved this by writing a simple python uno script which communicates with the libreoffice process and closes all documents. This will remove the lock files:

I know that the code isn't perfect. So help from anybody is very appreciated.

import uno

# Connect to LibreOffice
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager

# Create new XDesktop instance
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

# Load all documents Components
componentsEnumerator = desktop.getComponents().createEnumeration()

# Default value if any component isn't able to close
closeDenied = False

# Iterate through all Components
while componentsEnumerator.hasMoreElements():
    # Load document
    document = componentsEnumerator.nextElement()

    # Is close supported?
    if not hasattr(document, "close"):
        continue

    # Try to close it regulary
    try:
        document.close(True)   
    except:
        # Dispose the frame of this component
        document.getCurrentController().getFrame().dispose()

ctx.ServiceManager