Page 1 of 1

[Solved] Detect Operating System

Posted: Fri Jan 08, 2010 1:18 am
by Heertsch
Is there a way to detect, on which Operating System OOo Basic runs?

Re: Detect Operating System

Posted: Fri Jan 08, 2010 2:32 am
by RPG
Hello


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
From the macro help file

Romke

Re: Detect Operating System

Posted: Fri Jan 08, 2010 10:35 am
by Heertsch
Thanks, works fine!
Andreas

Detect Operating System

Posted: Mon May 03, 2010 9:34 pm
by Heertsch
the GetGUIType() function sends 4 (Unix) on MAC OSX
Is there a way to distinguish Mac OSX and other Unix?

Detect Operating System

Posted: Mon May 03, 2010 11:38 pm
by Heertsch
Ok,here my (quick and dirty) solution:

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
I hope someone has a better approach. (to interpret the PATH enviroment variable may be dangerous... :knock: )
Andreas

Re: [Solved] Detect Operating System

Posted: Tue Aug 10, 2010 8:26 pm
by MrProgrammer
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

Re: [Solved] Detect Operating System

Posted: Fri Jan 28, 2011 4:42 am
by james_h
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:

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

Posted: Fri Jan 28, 2011 1:43 pm
by RPG
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

Re: [Solved] Detect Operating System

Posted: Wed Feb 16, 2011 8:15 pm
by james_h
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