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?
@Pansmanser Did you try the basic/Python solution presented by @librebel ( original suggestion by @karolus )? On my Mint system it returns Linux
. Don’t have others to test, but have no reason to believe it won’t work.
Thanks, @Ratslinger - I’m trying the @librebel/@karolus solution, as shown above. Meanwhile, environ(“MACHTYPE”) and environ(“OSTYPE”) return null strings on my sys and are not present when I list environment variables.
Thanks, @Ratslinger - I’m trying the @librebel/@karolus solution, as shown above. Meanwhile, environ(“MACHTYPE”) and environ(“OSTYPE”) return null strings on my sys and are not present when I list environment variables.
@Pansmanser Running set | less
using terminal will only display the first page initially. At the :
prompt did you press enter or down arrow for more entries? It can be a long list which is the reason to display ‘less’.
@Ratslinger Thanks for that. Yes, set | less (how do you do that highlighting?) throws up MACHTYPE and OSTYPE. However they are still not detected by environ(). Any fix for that?