[Solved] Detect Operating System
[Solved] Detect Operating System
Is there a way to detect, on which Operating System OOo Basic runs?
Last edited by Villeroy on Fri Jan 08, 2010 10:46 am, edited 1 time in total.
openOffice 3.2 on Windows 7 / Mac OSC 10.5 / Ubuntu 10.4
Re: Detect Operating System
Hello
From the macro help file
Romke
Code: Select all
GetGuiType Function [Runtime]
Returns a numerical value that specifies the graphical user interface.
This runtime function is only provided for downward compatibility to previous versions. The return value is not defined in client-server environments.
Syntax:
GetGUIType()
Return value:
Integer
Return values:
1: Windows
3: Mac OS
4: UNIX
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Re: Detect Operating System
Thanks, works fine!
Andreas
Andreas
openOffice 3.2 on Windows 7 / Mac OSC 10.5 / Ubuntu 10.4
Detect Operating System
the GetGUIType() function sends 4 (Unix) on MAC OSX
Is there a way to distinguish Mac OSX and other Unix?
Is there a way to distinguish Mac OSX and other Unix?
openOffice 3.2 on Windows 7 / Mac OSC 10.5 / Ubuntu 10.4
Detect Operating System
Ok,here my (quick and dirty) solution:
I hope someone has a better approach. (to interpret the PATH enviroment variable may be dangerous...
)
Andreas
Code: Select all
'==========================================
'determine Operating System
'==========================================
function OS()as string
select case getGUIType
case 1: OS="WINDOWS"
case 3: OS="MAC"
case 4: OS=iif(instr(environ("PATH"),"openoffice")=0,"OSX","UNIX")
end select
end function

Andreas
openOffice 3.2 on Windows 7 / Mac OSC 10.5 / Ubuntu 10.4
- MrProgrammer
- Moderator
- Posts: 5281
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: [Solved] Detect Operating System
Of course, under the covers a modern Mac system is UNIX (with a really nice front end), so 4 (UNIX) might be a reasonable answer on that platform -- it depends on what you're going to do with this information. But one idea might be to look at the OSTYPE or MACHTYPE environment variables, which on my machine are:
OSTYPE=darwin10.0
MACHTYPE=x86_64-apple-darwin10.0
OSTYPE=darwin10.0
MACHTYPE=x86_64-apple-darwin10.0
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: [Solved] Detect Operating System
The function fails on a fork of OpenOffice.org because the function looks for "openoffice", not "libreoffice" or other program directory name.
I adapted the function as follows. It should work for forks:
I adapted the function as follows. It should work for forks:
Code: Select all
Function SpeechEngine()as string
select case getGUIType
case 1: SpeechEngine=iif(fileExists (fsProgramDirectory & "eSpeak\command_line\espeak.exe"),"ESPEAK","SAPI") 'Win
case 3: SpeechEngine=iif((fileExists("/usr/bin/espeak") or ifileExists("/usr/local/bin/espeak")),"ESPEAK","SAY") 'Old Mac
case else: SpeechEngine=iif((fileExists("/usr/bin/espeak") or fileExists("/usr/local/bin/espeak")),"ESPEAK","SAY") 'Posix
end select
end Function
Function fsProgramDirectory
Dim c as string
c = environ("ProgramFiles")
if instr(c, "\") <> 0 then
fsProgramDirectory= c & "\"
else
fsProgramDirectory="/usr/bin/"
end if
End Function
Re: [Solved] Detect Operating System
Hello
I have test the code given by Heertsch and it works also with LibreOffice. Maybe the problem you get is by the IIF.
http://www.openoffice.org/issues/show_bug.cgi?id=63614
There is a known bug with this code. When you store and close the file and then load again then it is working. I'm not sure if I have to close OOo complete. For this reason I donot use IIF.
http://www.openoffice.org/issues/show_bug.cgi?id=63614
You can use maybe: switch
Romke
I have test the code given by Heertsch and it works also with LibreOffice. Maybe the problem you get is by the IIF.
http://www.openoffice.org/issues/show_bug.cgi?id=63614
There is a known bug with this code. When you store and close the file and then load again then it is working. I'm not sure if I have to close OOo complete. For this reason I donot use IIF.
http://www.openoffice.org/issues/show_bug.cgi?id=63614
You can use maybe: switch
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Re: [Solved] Detect Operating System
This script should avoid a false identification as OSX for UNIX or LINUX systems using an alternate directory name like libreoffice instead of openoffice.
Code: Select all
Function getOS()as String
Select Case getGUIType
Case 1:
getOS="WINDOWS"
Case 3:
getOS="MAC"
Case 4:
If Instr(Environ("PATH"),"openoffice")=0 And Instr(Environ("PATH"),Lcase(fsGetSetting("ooname")))=0 Then
getOS="OSX"
Else
getOS="UNIX"
Endif
End Select
End Function
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