// as of 10.4 apple provides 3 selectors so we can get the correct version number for things like 10.4.11
Dim sysMajorVersion,sysMinorVersion,sysBugVersion As Integer
call System.Gestalt(“sys1”, sysMajorVersion)
call System.Gestalt(“sys2”, sysMinorVersion)
call System.Gestalt(“sys3”, sysBugVersion)
Public Function appKitVersionNumber() as double
// Const appKitVersionNumber10_8 = 1187
// Const appKitVersionNumber10_9 = 1265
// Const appKitVersionNumber10_10 = 1328
Declare Function dlopen Lib "System" ( path As CString, mode As Integer ) As ptr
Declare Function dlsym Lib "System" ( handle As PTr, name As CString ) As ptr
Const RTLD_LAZY = 1
Const RTLD_GLOBAL = 8
Dim libPtr As ptr = dlopen( "/System/Library/Frameworks/AppKit.framework/AppKit", RTLD_LAZY Or RTLD_GLOBAL )
If libPtr = Nil Then return 0
Dim rvalue as Ptr = dlsym( libPtr, "NSAppKitVersionNumber" )
if rvalue <> nil then return rvalue.double
End Function
Public Function OSVersion() as OSVersionInfo
Dim rvalue As OSVersionInfo
If appKitVersionNumber >= appKitVersionNumber10_10 Then
// --- We're using 10.10
Declare Function NSClassFromString Lib "AppKit" ( className As CFStringRef ) As Ptr
Declare Function processInfo Lib "AppKit" selector "processInfo" ( ClassRef As Ptr ) As Ptr
Dim myInfo As Ptr = processInfo( NSClassFromString( "NSProcessInfo" ) )
Declare Function operatingSystemVersion Lib "AppKit" selector "operatingSystemVersion" ( NSProcessInfo As Ptr ) As OSVersionInfo
rvalue = operatingSystemVersion( myInfo )
Else
Dim major,minor, bug As Integer
Call System.Gestalt( "sys2", major )
Call System.Gestalt( "sys2", minor )
Call System.Gestalt( "sys3", bug )
rvalue.major = major
rvalue.minor = minor
rvalue.bug = bug
End If
Return rvalue
End Function
Public Function osVersionHumanReadable() as string
#if TargetMacOS then
declare function NSClassFromString lib "AppKit" ( className as CFStringRef ) as Ptr
declare function processInfo lib "AppKit" selector "processInfo" ( classRef as Ptr ) as Ptr
dim myProcess as Ptr = processInfo( NSClassFromString( "NSProcessInfo" ) )
declare function operatingSystemVersionString lib "AppKit" selector "operatingSystemVersionString" ( NSProcessInfo as Ptr ) as CFStringRef
return operatingSystemVersionString( myProcess )
#endif
End Function
yes it is more “code” but for OSX10.10.0 and above it skips the deprecated GESTALTS
[quote=318764:@Kem Tekinay]dim sh as new Shell
sh.Execute _
“/usr/bin/sw_vers | /usr/bin/awk ‘/ProductVersion\s*(.*)/{print $2}’”
dim osVers as string = sh.Result.Trim[/quote]