… The reason I ask this is because after playing around with this a little, and especially when getting .nodename
, .release
, .version
, and .hardware
from os.uname()
, I noticed that for me os.uname().hardware
is not working, BUT … if I return os.uname()
as an array, I then get the hardware info. And also I get Linux
(capitalized, instead of lower case). This is strange. Seems flaky. Just say’n.
In this particular case the arrays do nothing, since get_OS() has no parameters… If the value of a passed argument is changed by a function, the updated value can be retrieved afterwards from the aOutParam() array.
Figured out the user / share thing. There are two places to put python code. Run this to list them:
Function getPythonPaths()
Dim oPathSettings As Object : oPathSettings = createUnoService("com.sun.star.util.PathSettings")
Dim s As String
Dim sMsgBox As String
For Each s In Split(oPathSettings.Basic,";")
sMsgBox = sMsgBox & left(s,len(s)-len("/basic")) & "/Scripts/python" & chr(10)
Next
msgbox sMsgBox
End Function
Win users please adjust slash.
This is evidently a promising approach for us basic users. However I am getting a script framework error exception at the line beginning ‘oScript =’ with the message “unsatisfied query for interface of type com.sun.star.script.provider.XScriptProvider” (Ubuntu 16.04, LO 5.1.6.2)
Thanks @Ratslinger for help in this. I saved get_os.py to
/home/robert.config/libreoffice/4/user/Scripts/python. I had to create Scripts/python.
(Is the script it meant to end with that comma?)
Also ran @EasyTriee’s GetPythonPaths macro to locate the paths. The other path displays as file:///usr/lib/libreoffice/program/…/share/Scripts/python, but it didn’t seem to match the file structure. Not sure what’s missing at …, but nothing looks right below program.
@Pansmanser, error relates to this section: get_os.py$get_OS?language=Python&location=user"
Check upper lower case. Note his filename is lower case and his function is mixed case. I stumbled over this at first, then regularized the names to get_OS.py, and get_OS. Perhaps that is the issue. Also, do you mean /home/robert/.config/libreoffice/4/user/Scripts/python
? (had missing slash in your comment). If dirs are missing, then create them as needed.
according to this (old) source the share directory for Python scripts is typically located at:
windows C:\Program Files\ [Office] \share\Scripts\python
unix ... /user/Scripts/python
here it is “share” again:
ubuntu 10.04 /usr/lib/openoffice/basis3.2/share/Scripts/python
Thankyou, @EasyTrieve & @librebel.
Yes, my location, function name and call to ScriptProvider are exactly as you write them, @EasyTrieve. (a misprint in my previous comment, as you point out).
I’ve duplicated …/user/Scripts/python at …/share/Scripts/python without success, @librebel. EasyTrieve’s function GetPythonPaths suggests that ‘user’ is correct in the /home, but ‘share’ would be correct in the global /usr (although I don’t understand the full path in the latter case).
Problem now (partially) solved by @Ratslinger. I did not have the python script provider installed. Does it work in OSX?
Next to the above mentioned Python hints, my take for a solution using Basic language is:
Option Explicit
Sub Main : MsgBox OSName : End Sub
Function OSName As String
''' Return platform name as "MAC", "UNIX", "WIN" '''
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
Dim keyNode As Object ' com.sun.star.configuration.ConfigurationAccess '
keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help")
OSName = keyNode.GetByName("System")
' inferred from "Tools.UCB.ShowHelperDialog" '
End Function ' (Tools).OSName
Yes.
I’ve tested this on OSX 10.10.3 and Windows 7
Here’s the macros I’m using - notice the references to OO
global OStext as string
global OScode as integer
global FileSystemDelimite as string
sub TestOS
call getOS
print OSText
end sub
public Sub getOS()
Select Case getGUIType
Case 1:
OStext="WINDOWS"
OScode=1
FileSystemDelimiter="\"
Case 3:
OStext="MAC"
OScode=3
FileSystemDelimiter="/"
Case 4:
If Instr(Environ("PATH"),"openoffice")=0 And Instr(Environ("PATH"),Lcase(fsGetSetting("ooname")))=0 Then
OStext="OSX"
OScode=4
FileSystemDelimiter="/"
Else
OStext="UNIX"
OScode=5
FileSystemDelimiter="/"
Endif
End Select
End sub
Function fsGetSetting(sA)
GlobalScope.BasicLibraries.LoadLibrary("Tools")
Dim oProdNameAccess As Object
oProdNameAccess=GetRegistryKeyContent("org.openoffice.Setup/Product")
Select Case Lcase(sA)
Case "language"
fsGetSetting=GetStarOfficeLocale().language
Case "country"
fsGetSetting=GetStarOfficeLocale().country
Case "ooname"
fsGetSetting=oProdNameAccess.getByName("ooName")
Case "ooversion"
fsGetSetting=oProdNameAccess.getByName("ooSetupVersion")
Case Else
fsGetSetting="???"
End Select
End Function
Unfortunately, this incorrectly says my Linux Debian 8.5 / LO 5.2.5.1 is OSX.
Because ‘openoffice’ is not in the path (nor LO) and ‘ooname’ is not detected. Again, I don’t think PATH can be used to do this.
No, it does not work on LibreOffice. I don’t actually see how the PATH helps to distinguish Linux from OSX, which is based on Linux. If that Python trick works, then it is frustrating that the Basic GetGUI call is incomplete. The same source from which jay Arr took his code suggests inspecting environment variables OSTYPE and MACHTYPE, but they don’t appear to exist in Ubuntu. In trying to solve this problem, I’ve been looking for other env var’s common to OSX, Win & Linux, but haven’t got anything useful yet.
OSTYPE and MACHTYPE on Mint 18 show as MACHTYPE=x86_64-pc-linux-gnu
, OSTYPE=linux-gnu
.
use set | less
to list.
Ubuntu 16.04:
MACHTYPE=x86_64-pc-linux-gnu
OSTYPE=linux-gnu
Anybody help with the OSX results?