The format to automatically run a macro when opening a document via the command line is missing from the LibreOffice help. This is needed to automate workflows using scripts.
Steps to Reproduce:
1.Look in the help
Suggested text: To run a macro on startup from the command line or a script the format is soffice FileName macro:///Path.To.Macro
FileName is the full file name of the document/spreadsheet
Path.To.Macro is the full path to the macro as seen in the LireOffice Basic Macros dialog window.
So an example to open a spreadsheet and execute a macro named Startup in Module1 would be:
soffice MyFile.ods macro:///Standard.Module1.Startup
User Profile Reset: No
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0
I confirm it.
tagezi committed a patch related to this issue.
It has been pushed to "master":
tdf#104441 Addition to output to the console help
It will be available in 5.4.0.
The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
Affected users are encouraged to test the fix and report feedback.
This patch was for output to the console.
For online and build-in Help it was added in https://gerrit.libreoffice.org/gitweb?p=help.git;a=commitdiff;h=47ad5a2f2102740bda4cf02dcd73562da79f67a9
So, I think that it is fixed.
If you have any comments, I am ready to listen.
I wanted to amend the information as available on http://www.script-coding.com/OOo/OOo_HelloWorld.html:
You can execute a macro from a command line, like this:
> soffice -invisible macro:///standard.module1.mymacro
Here "standard" is a name of a library from "My macros" container, "module1" - module name, "mymacro" - name of function (sub) of macro itself. This will start a LibreOffice process, which will execute the macro and exit.
You can start a macro of a specific document at its opening from a command line:
> soffice path/to/test.odt macro://./standard.module1.mymacro
If e.g. test1.odt document is already opened, this command line will also work:
> soffice macro://test1/standard.module1.mymacro
A macro may be executed from another macro code (using similar URLs), like this:
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
sMacroURL = "macro:///standard.module1.mymacro"
oDisp.executeDispatch(StarDesktop, sMacroURL, "", 0, Array())