I have a file hello.odt. I’d like to run a Python macro from the command line and have access to hello.odt from within the macro.
I’ve tried:
soffice hello.odt 'vnd.sun.star.script:myscript.py$Hello?language=Python&location=share'
This is my python script:
import sys
def Hello(*args):
# get the doc from the scripting context which is made available to all scripts
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
# the print statement is here only for debugging purposes
# "model" should be the currently opened document
print(model)
# then do stuff with the document...
The script doesn’t seem to see “model” and prints “None”. My ultimate goal is to generate the table of contents by invoking “.uno:UpdateAllIndexes”. But first I need access the document. That’s why i’m printing out “model”.
This answer suggests opening the file, then wait 3 seconds for office to launch, then run the macro. But I find it odd.