Best macro to detect the operating system

Yee-hah!! and Halellujah! Solved! I was starting to suspect that my LO was incomplete. Thanks @Ratslinger.

OK this works, and I hate to be ungrateful. BUT my jubilation may be premature. It requires the python script to be installed on every machine on which you need to use it, which makes it not very portable. And I don’t know if it would work on OSX, which was why I started down this track. @Ratslinger, is there any chance of making the OSTYPE method work?
Or can python scripts be embedded, as with basic?

@Pansmanser Not really ready to figure out another method. I am fairly certain the script is the way to go. Yes it can be embedded in the .odb (which is the ‘document’ setting). Please ask as a NEW question - How to embed Python script in document. This will make it available to others searching for it. Also the answer requires more room than allowed here.

Here’s a little Form tool based on @librebel 's code here to make it a slight bit easier to install and test this feature, (… cause I want to find someone to test this on OSX and other OS’s to make sure this works.)

Run the ‘Form to get OS using Python call’ to help you setup and test this feature.

image description

(There’s a few hours I’ll never get back, but it was fun.)

Edits:

  • Added a comma after g_exportedScripts = line, as per @librebel 's comment. No harm I guess, as it might break for someone w/o it.
  • Also I should note that I took liberty to regularized the name so get_OS is both the filename and function name. (Before the filename was get_os.py, lower case. Hope I’m not breaking any rule here.)

Nice job @EasyTrieve… one note about the “g_exportedScripts”, it expects a string list which defines the python functions within your .py-file that are made executable from within LibreOffice. If there is no more than 1 function name in the string list, it should for some reason end with a comma, e.g.:

g_exportedScripts = macro1,

for 2 or more exported functions:

g_exportedScripts = macro1, macro2

@Librebel, Thanks. Humm? It works for me without the comma. Figured w/ python’s zest for brevity, it was worth a try. Can’t find official documentation on g_exportedScripts. But from DuckDuckGo g_exportedScripts I can see that others use it w/ a comma. Only thing I can figure is it might need a comma in older or newer versions. my: python --version gives “2.7.9”. What’s your version?

The comma at the end of one item makes it a tuple. See documentation.

@Ratslinger now it make sense … however when i put a single method name inside tuple brackets () it still requires the extra comma.
Perhaps it must be a 2-tuple at the least, where the second element may be empty…
@EasyTrieve my Python version is 3.5.2 … but i also have 2.7 installed from before :slight_smile:

@Ratslinger, thanks, that’s interesting. @librebel, the ‘documentation’ Ratslinger mentions says this: “Note that it is actually the comma which makes a tuple, not the parentheses.” …And looks like I’ve got some more updating to do.