System Version

Is there a way to retrieve the version of the OS the app is running under. In other words, can I get the versions of Mac OS X?

In FileMaker, there is a lot of information that can be retrieved. I have looked at App, Application, and System and haven’t seen the OS Version.


// 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)

Now you have all the correct OS X values

You can also call /usr/bin/sw_vers on the command line and parse the output. On my system, the result looks like this:

ProductName:	Mac OS X
ProductVersion:	10.12.3
BuildVersion:	16D32

Hasn’t Gestalt been deprecated?

Deprecated ? removed
Works fine still

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 )
    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 )
End Function

yes it is more “code” but for OSX10.10.0 and above it skips the deprecated GESTALTS

		appKitVersion.text = str( appKitVersionNumber )
		displayVersionString.text = osVersionHumanReadable
		Dim ovi as OSVersionInfo = OSVersion
		versionnumbers.text = str( ovi.major ) + "." + str( ovi.minor ) + "." + str( ovi.bug )

For the same of completeness:

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

If you have MBS it is:


I had tried to do it manually, but Windows versions clashed in what OS number they thought they were!

[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]

Smile. Bonus points for using awk!

MBS Plugin users can use the SystemInformationMBS module

In General you should not check for version but for features you need.
That is the reason I include a lot of available functions.