Ask Your Question
0

Why does environ return some variables and not others

asked 2018-05-19 19:01:51 +0200

Mirador gravatar image

updated 2018-05-19 19:13:43 +0200

I have an issue with LO whereby the environ function will return some values like PATH, but not others like OSTYPE and MACHTYPE. I tried to use GetGUIType() to determine which operating system I am running so I can run the appropriate e-mail code, but it returned 3 (MAC) although I am running on a Linux system! As much as I'd like to be able to afford a Mac, this is clearly incorrect, so I have tried to roll my own function based on interpreting certain environment variables.

In a command windows I can see these:

MACHTYPE=x86_64-pc-linux-gnu
OSTYPE=linux-gnu

However, the environ function seems to be very selective about which variables it returns values for and returns a null string for these although it correctly returns the values of other environment variables.

edit retag flag offensive close merge delete

Comments

Have you tried to extract info about OS type using values from PATH variable? The variable is different in Windows, Linux and Mac.

Xoristzatziki gravatar imageXoristzatziki ( 2018-05-20 18:00:03 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-05-19 19:28:34 +0200

Ratslinger gravatar image

updated 2018-05-20 20:45:21 +0200

Hello,

Please see answer by @librebel & @karolus in this post -> best macro to detect the operating system

Edit 2018-05-19:

If you do a search on this forum you will see numerous postings for Python.

Here are some relevant links (not all from this forum):

Missing Python in LibreOffice organize macros menu

Transfer from Basic to Python

Basically python scripts reside in system, user or document storage. To embed a script in document see the EmbedPythonScriptInDocument.odt file in my answer here -> Can I embed python script and integrate with basic?

Interaction -> Christopher Bourez's blog

More here -> Information and resources for LibreOffice macros

Well, that's just some of it. There is a bunch more on the subject but that should easily get you started. Much more than I had. Found all this & more on my own when starting python & LO a couple of years ago.

Edit 2018-05-20:

Used seperate disk sitting around with almost nothing done to it after a Ubuntu 17.04 Mate install. Removed all traces of LibreOffice. Had LO 5.4.5.1 around (this is from TDF) and installed. Immediately after install ( nothing else done), the following were present:

Script provider for BeanShell extension for LibreOffice 5.4 .5.1
Script provider for JavaScript extension for LibreOffice 5.4 .5.1
Script provider for Python for LibreOffice 5.4 .5.1

Was now able to:

  • From menu Tools->Macros->Run Macro... & from LibreOffice Macros successfully run HelloWorldPython & pythonSamples->TableSample->createTable both Python.

  • install LO extension I wrote, completely in python, for Calc. Executes from Toolbar. Ran without problem including various functions within dialog.

  • Inserted a pushbutton on Calc sheet. Connected Execute action event to various python scripts in MyMacros and all ran without a problem

Works for me.

If this answers your question please tick the ✔ (upper left area of answer). It helps others to know there was an accepted answer.

edit flag offensive delete link more

Comments

Thanks for the very quick reply and references! I could use python on my development system, however I cannot assume that the person I send the spreadsheet file to will have python installed on their system.

It seems evident from that thread that this issue is several years old. I am surprised that the functions have not been fixed.

Mirador gravatar imageMirador ( 2018-05-19 19:54:54 +0200 )edit

Incidentally, Linux has a file called vmlinuz in the root directory (/) so I thought I could use this and specify //vmlinuz instead. It takes several seconds to search while when I use //vmlinuz but it pretty much instant with /vmlinuz, not sure why the difference, nevertheless it returns FALSE on both so I'm scuppered again! It will return TRUE on any other file in my home directory. I have no problem seeing vmlinuz in a command window with the ls command.

Mirador gravatar imageMirador ( 2018-05-19 19:55:04 +0200 )edit

If there is no other way then I might have to make this a manual process by using some kind of dialogue to ask the user. I need to do some research how to do this first.

Mirador gravatar imageMirador ( 2018-05-19 19:55:14 +0200 )edit

If LO is installed then python is there. Much of LO runs on it.

Ratslinger gravatar imageRatslinger ( 2018-05-19 19:59:54 +0200 )edit

I couldn't run a Python script from the command line on a Windows PC with LO installed. In calc, I see Python as an option for macros and a couple of sample macros in the organizer, but all organizer options are greyed out so macros cannot be run or edited.

On my Linux PC there is no option for Python under macros. I can run a python script from the command line but only because I had installed it some time ago for another project.

If Python is part of LO, how does one access it?

Mirador gravatar imageMirador ( 2018-05-19 22:48:55 +0200 )edit

BTW, would be happy to develop macros using Python, if it is available by default consistently across platforms, the macro is easily portable within the spreadsheet file and does not inconvenience the end user with technical difficulties (i.e having to install extras or make configuration tweaks).

BTW, Windows is actually not an issue as the OS is detected OK. The problem is differentiating Linux from OSX.

Mirador gravatar imageMirador ( 2018-05-19 22:55:47 +0200 )edit

In UBUNTU libreoffice-script-provider-python is not installed by default. You have to install python scripting support for LO. This gui can be used to insert a python script to document, or try the above already mentioned links.

Xoristzatziki gravatar imageXoristzatziki ( 2018-05-20 09:07:22 +0200 )edit

"You have to install python scripting support for LO." This is the problem. The install package is not consistent across platforms. This has to be foolproof. I can't expect the end user to be IT literate and deal with such an issue.

The gui looks interesting and I will test it later. In the sample.bas that seems a horribly complex way of saying 'run this script'! The readme suggests it can run directly from hyperlink, but how do I specifiy the [doc.ods] bit? I couldn't get any script to run.

Mirador gravatar imageMirador ( 2018-05-20 10:06:37 +0200 )edit

Having checked multiple Linux installs (Mint 18.3 Cinnamon, Mint 18 KDE and Ubuntu 18.04) all run Python macros from menu without anything extra being installed. Lo versions ranged from 5.3.x to 6.0.4. It appears you are running an older version and from appearance a distro version. This may be the problem.

As far as "foolproof" good luck with that. Never seen that. Problems happen in OS, LO distro releases etc. all the time.

Ratslinger gravatar imageRatslinger ( 2018-05-20 16:39:00 +0200 )edit

Having installations of UBUNTU 14.04 (support ends April 2019) and UBUNTU 16.04 (support ends April 2021) and UBUNTU 18.04 (released less than a month ago... a.k.a. still an infant:-), all fully updated, checked that none of these install by default the script provider. What you can do (...if you can give someone instructions to find a python script using menus) does not mean you can use these scripts as macros without installing the script provider.

Xoristzatziki gravatar imageXoristzatziki ( 2018-05-20 17:35:46 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-19 19:01:51 +0200

Seen: 71 times

Last updated: May 20 '18