Running a macro from libreoffice command line

Hi,

this macro code from @karolus does what I want:

Sub TESTING
dim pages(0) as new com.sun.star.beans.PropertyValue
dim props(1) as new com.sun.star.beans.PropertyValue
pages(0).Name="PageRange"
pages(0).Value="2-4"
props(0).Name= "FilterName"
props(0).Value= "writer_pdf_Export"
props(1).Name= "FilterData"
props(1).Value=pages()
doc = ThisComponent
uri = convertToURL("/home/wertie/PDF/test.pdf")
doc.storeToURL(uri,  props())
End Sub

…but I want to run it headless. I suspect there’s a bug in the python wrapper, since the same operations fail if I use it. I’m not sure how to send BASIC to a remote libreoffice process, so tips on that would be appreciated as well.

Anyway, I saw there is some kind of command line kludge to do this, which isn’t mentioned in the man page or any docs I’ve seen. I’d really appreciate a pointer on this.

Using the kludge, I tried running the above script like this:

libreoffice --headless "macro:///Standard.Module1.TESTING("test.odt"))

and it produced nothing. Then I ran it without --headless:

libreoffice "macro:///Standard.Module1.TESTING("test.odt"))

and it ran but produced the error message:

BASIC runtime error
Property or method not found: storeToUrl

Do I need to import something from inside the subroutine?

Any tips greatly appreciated, and thanks everybody for your help so far!

no magical parameter, you have to define it …

and libreoffice --headless 'macro:///Standard.Module5.prnt' p7.odt seems to just hang.

so, use loadComponentFromURL from Macros/Basic/Documents - The Document Foundation Wiki
with

args(0).Name = "Hidden"
args(0).Value = True