Soffice called from a command line specifying a macro: How can the macro see the command (parameters)?

It’s well known how to call LibreOffice (soffice) from a terminal / shell. It may then open a file in different modes and/or run a macro.
However, the macro doesn’t get passed any arguments, and I can’t find a way to see them / the command line.
Example:

C:\Users\user>soffice "vnd.sun.star.script:Standard.zzXX.treatFile?language=Basic&location=application&filepath=C:\Users\user\Documents\_some\expl.ods"

The macro is called as expeceted, but doesn’t see an argument as if it were called from a link inside a document. Generally I would expect that the API gives access to a command line or otherwise to the parameters soffice was called with (last time if multiply).

1 Like

Perhaps I did not understand the idea …

For me, a line like

soffice.exe C:\Users\user\Documents\_some\expl.ods macro:///Standard.zzXX.treatFile(param1,param2)

and code

Sub treatFile(Optional a,Optional b,Optional c)
	If IsMissing(c) Then 
		If IsMissing(b) Then 
			If IsMissing(a) Then 
				Print "No param"
			Else 
				Print "1 param =" & a
			EndIf
		Else 
			Print "2 params a=" & a & " and b=" & b
		EndIf
	Else 
		Print "3 params a=" & a & ", b=" & b & " and c=" & c
	EndIf
End Sub

open file and gives the result
image

3 Likes

That’s not acceptable!
Not understanding must continue to be my privilege.

Thanks for your example anyway.

As so often: I do not actually need the solution, but there are probably senile thoughts.

  1. We need a clear way to distinguish macros by their location.
  2. If LibreOffice (soffice) is to get a task, it should be possible, for example, to name a document to be treaterd instead of opening it primarily. This may better be left to the macro.
  3. If there is a well proven method to call a macro via vnd.sun.star.script:, it should also be available for calls from the command line. Actually this is implemented, but …
  4. A few decades ago when I occasionally programmed and compiled little helpers or toys with a stand-allone programming system, the programs always got transmitted the calling command, and I could evaluate it for options and arguments - just like if I call a macro from a document-contained link and analyze the query part. Why can’t I see the command soffice got? ( At least the last one if it was active already in advance.)

This thesis causes me stormy indignation! We are all equal before the soffice - each of us should have this privilege! :rofl:

Isn’t that what ScriptForge is trying to implement - the fully qualified method name uniquely specifies the location? (I’m not claiming that something good came out of this - perhaps the time has not yet come … we wait …)

Senile thought: let’s pass the file name as a parameter to the macro and let the macro decide whether it wants to open this file (or just execute Kill)

Perhaps this method of calling can be considered “well proven”, but I absolutely do not like it! (Perhaps because I constantly confuse the “dot” and “comma” buttons and this construction has to be rewritten several times? macro:///Standard. is much better, there are much fewer dots :wink:). It may well be that parameter passing has already been implemented, but not documented, and a pleasant discovery awaits us. Or just now someone is working on an implementation - something in curly braces, JSON-like, who knows?