Can I embed python script and integrate with basic? (solved)

There is a very useful python script by @librebel to detect the current os:

To make it portable it can be embedded in the document. This is beautifully explained by Christopher Bourez here:

Now the question: how can I call the embedded python script from basic?

Thank you @Pansmanser, only by this very good idea of yours, to embed the get_OS() python script into a document, does it become useful. Btw it was i who wrote it.

@librebel Appreciated your article (read a while back) but you may want to check out APSO in the document I attached in my answer.

sorry i might have missed that part ( i have installed APSO ) … i meant to say that the python script to detect the current os was not written by karolus and EasyTrieve, but by me.

Got it. It was still a good article and your script was OK too.

Sorry if I’ve misunderstood. I think I attributed it to you in my question, @librebel.

No problemo amigos, thanks for the credits:) … i’ll search if there is a way to embed the Python script in the user’s document by code. However for that macro to work, the user should also have the libreoffice-script-provider-python installed.

@librebel Not clear on your purpose to ‘embed the Python script in the user’s document by code.’ What is that vs what is already done in APSO?

@Ratslinger, i thought it would be nice if the method that depends on the python script “get_OS” would automatically install that python script for the user. Be it inside their document, or in the user or share location.
… having connection difficulties, 1 of my comments was lost after posting it

Some of my recent searching reveals embedding Python scripts in a LO document can done by manipulating the data in files within the zipped document. However effective this is, it is prone to error.

I have found much simpler way to do this. As the images I have used take considerable space, I have attached a document with all the necessary information. It is a very simple procedure.

As for the call in basic, change the basic script from:

oScript = oScriptProvider.getScript( "$get_OS?language=Python&location=user" )


oScript = oScriptProvider.getScript( "$get_OS?language=Python&location=document" )

Note: The only thing changing is at the end of the line: ‘user’ to ‘document’.
Test the script.

Attachment: EmbedPythonScriptInDocument.odt

If this answers your question please click on the :heavy_check_mark: (upper left area of answer).

+1 @Ratslinger that is awesome! i hadn’t noticed the “Embed in Document” menu before…
Thanks for your handy manual, and thank you @Hanya for APSO !

@librebel I can’t believe you didn’t see that even after the comment I made previously about the duplicating effort in a macro. BTW there were two people involved. Hubert Lambert was the other beside Hanya. Props to both.

yes sorry Ratslinger, ma bad, i was commenting too quickly while i had not yet taken the time to read all notifications…
Thanks indeed at Hubert Lambert too for APSO! … Have they ever appeared in this forum ?

Never know. Have not seen, at least with those names.