dim sys1, sys2 as Integer
//be more specific
call System.Gestalt("sys1", sys1)
call System.Gestalt("sys2", sys2)
select case sys1
case 10 //os="Mac OS X"
select case sys2
case 6
OSX_Name="Snow Leopard"
case 7
OSX_Name="Lion"
case 8
OSX_Name="Mountain Lion"
case 9
OSX_Name="Mavericks"
case 10
OSX_Name="Yosemite"
end Select
end Select
Dim noerror As Boolean
Dim result As Integer
Dim sversion As String
Dim os As String
Dim sysMajorVersion,sysMinorVersion,sysBugVersion As Integer
#If TargetMacOS
Call System.Gestalt("sys1", sysMajorVersion)
Call System.Gestalt("sys2", sysMinorVersion)
Call System.Gestalt("sys3", sysBugVersion)
noerror=System.Gestalt("sysv",result)
sversion=Str(sysMajorVersion) + "." + Str(sysMinorVersion) + "." + Str(sysBugVersion)
Select Case sysMajorVersion
Case 10
Select Case sysMinorVersion
Case 0
os="Cheetah"
Case 1
os="Puma"
Case 2
os="Jaguar"
Case 3
os="Panther"
Case 4
os="Tiger"
Case 5
os="Leopard"
Case 6
os="Snow Leopard"
Case 7
os="Lion"
Case 8
os="Mountain Lion"
Case 9
os="Mavericks"
case 10
os="Yosemite"
case 11
os="El Capitan"
Case Else
os="Unknown"
End Select
Case Else
os="Unknown"
End Select
Return "Mac OSX "+os+" "+sversion
#ElseIf TargetWin32
OS = "Windows"
//try to be more specific of windows version
Soft Declare Sub GetVersionExA Lib "Kernel32" ( info As Ptr )
Soft Declare Sub GetVersionExW Lib "Kernel32" ( info As Ptr )
Dim info As MemoryBlock
If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
info = New MemoryBlock( 20 + (2 * 128) )
info.Long( 0 ) = info.Size
GetVersionExW( info )
Else
info = New MemoryBlock( 148 )
info.Long( 0 ) = info.Size
GetVersionExA( info )
End If
Dim Str As String
If info.Long( 4 ) = 4 Then
If info.Long( 8 ) = 0 Then
os = "Windows 95/NT 4.0"
Elseif info.Long( 8 ) = 10 Then
os = "Windows 98"
Elseif info.Long( 8 ) = 90 Then
os = "Windows Me"
End If
Elseif info.Long( 4 ) = 3 Then
os = "Windows NT 3.51"
Elseif info.Long( 4 ) = 5 Then
If info.Long( 8 ) = 0 Then
os = "Windows 2000"
Elseif info.Long( 8 ) = 1 Then
os = "Windows XP"
Elseif info.Long( 8 ) = 2 Then
os = "Windows Server 2003"
End If
Elseif info.long(4) = 6 Then
If info.long(8) = 0 Then
os = "Windows Vista"
Elseif info.long(8) = 1 Then
os = "Windows 7"
End If
End If
Str = " Build " + Str( info.Long( 12 ) )
If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
Str = Str + " " + Trim( info.WString( 20 ) )
Else
Str = Str + " " + Trim( info.CString( 20 ) )
End If
os = os + Str
Return os
#EndIf
If memory serves, isn’t System.Gestalt ‘deprecated’? If so, it will go away at some point. It still works for now, but be aware that it might not be the safest way in the future.
No, these APIs won’t go away. When has Apple really made such core APIs go away before? Sure, Quicktime went away, but that’s not core tech. And some things may eventually break, such as Gestalt for “sysv” because it can’t represent the higher versions any more correctly. But all the old APIs are still around, for resources, for old file manager calls, and so on.
But for the record: The proper way on OS X to get the system version since OS X 10.10 (before that, it won’t work and you have to use the Gestalt operation) is to use NSProcessInfo.ProcessInfo.OperatingSystemVersion (should be in MacOSLib).
[code]Place this where you want your OS X Version information called from
Dim OSXVersion as String = fGetOS_Version(“System Version”,“SPSoftwareDataType”)
Function fGetOS_Version (optional Key as String, optional location as string) as String
// --------------------- GET OS X ENVIRONMENT INFORMATION FOR EMAIL SUPPORT HELP
Dim s as new Shell
Dim rvalue as string
s.Execute “system_profiler “+location+” | grep “+chr(34)+key+chr(34)
rvalue = trim(NthField(s.Result,”:”,2))
if rvalue <> “” then
Return rvalue
Elseif rvalue = “” Then
Return “unidentified”
end if
Jean-Yves, that’s an awfully wasteful solution. It’s almost as bad as using AppleScript to open the “About this macintosh” window, making a screen copy, uploading the image to a website for text extraction and then search the text for the OS version.
Never say never, FSRefs were deprecated in 10.8 and almost gone in 10.10! Caught so many developers out, as no-one expected Apple to remove file system operation APIs.
[quote=260374:@Tim Parnell]Sam made a Module that does it properly for Mac using Declares on systems that have them available: http://ohanaware.com/xojo/ [/quote]
Thanks Tim, it also falls back to Gestalt on a system where the more recent APIs are not available.
no because you only get a small part of systemprofiler : system_profiler SPSoftwareDataType
on my mac it return 12 lines that then go into grep to fetch the system version
[code]192:~ ioannis$ time sysctl -n machdep.cpu.brand_string
Intel® Core™ i5-2400 CPU @ 3.10GHz
real 0m0.003s
user 0m0.001s
sys 0m0.002s
[/code]
Kernel
[code]192:~ ioannis$ time uname -a
Darwin 192.168.1.2 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
real 0m0.002s
user 0m0.001s
sys 0m0.001s
[/code]
System version
[code]192:~ ioannis$ time sw_vers
ProductName: Mac OS X
ProductVersion: 10.11.4
BuildVersion: 15E65
yep systemprofiler is really longer than Loannis’s commands …
[code]$ time system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: OS X 10.9.5 (13F1712)
Kernel Version: Darwin 13.4.0
Boot Volume: disquedur
Boot Mode: Normal
Secure Virtual Memory: Enabled
If its one Appe added like system profiler it sure could
plutil has had significant changes over the years
And now for many things you need to use plist buddy instead of plutil