python script connect to writer document

Using python and uno I want to connect to an open document and, for example, save it.

The following code connects to libreoffice, but I don’t know how to connect to the file I have open in writer. Anyone know what comes next?

import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
            "com.sun.star.bridge.UnoUrlResolver", localContext )

# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager

Hi,

use this as starting point
https://github.com/kelsa-pi/PyUNO_Workspace/blob/master/simple_macro.py

This post may also be of help → Python IDE Basics

Hi carnish

Designing & Developing Python Applications wiki page may help you getting acquainted with Python script principles and tools. You can equally refer to LibreOffice Python Scripts Help (work in progress) whose content is not limited to 6.3 release.

To discover more you may be bound to translate existing Basic examples to Python, to explore LibreOffice API or run Python interpreter. Note that Apache OpenOffice Python wiki provides plenty of information that’s applicable to LibreOffice too.

Happy Python!