Recognize version of OS X

Hello guys,

          I'm having to update some parameters of my softwares to work well with Yosemite 10.10, what is the best way for me to check what version of OS X  the program is open, explain: 
          When open my softwares one of the functions is to check the serial number of the computer, it is different in pre-Yosemite compared to Yosemite, as I say, if Yosemite do "it" does not do "That", any help will be appreciated. 

Thank you so much!

Paulo,

This is the function I use to retrieve the OS X Version. I made the function have two passable values so indeed you could pass other system_profiler key/location values for other info it may bring back from your system. I am not using Yosemite so I can’t test that for you unfortunately.

HTH
Mike

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

don’t you think running the shell and letting system_profiler tons of information is not a little too much overhead for this?

maybe better use functions in MBS Plugin (or some declares)
https://www.monkeybreadsoftware.net/module-systeminformationmbs.shtml

Not the way I implemented it. Look at my code. I use it and it works well and very very fast.

Still a shell call, a tool which does some work and whenever the format changes of that output, it may break.

Same with your plugin in terms of changes :slight_smile:

But a very valid point non the less. :slight_smile:

[quote=134793:@Mike Cotrone]Paulo,

This is the function I use to retrieve the OS X Version. I made the function have two passable values so indeed you could pass other system_profiler key/location values for other info it may bring back from your system. I am not using Yosemite so I can’t test that for you unfortunately.

HTH
Mike

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

Hi Mike Cotrone

Actually I use a similar code but in Yosemite it does not work because the answer is not in line 2 but at 18 ( rvalue = trim(NthField(s.Result,":",2)) if I’m not mistaken, so I need to know which system runs the program.

Even so thank

[quote=134808:@Paulo Vargas]Hi Mike Cotrone

Actually I use a similar code but in Yosemite it does not work because the answer is not in line 2 but at 18 ( rvalue = trim(NthField(s.Result,":",2)) if I’m not mistaken, so I need to know which system runs the program.

Even so thank[/quote]

Paulo,

Sorry :slight_smile: If I had Yosemite I would find the values for you, but I don’t have it loaded yet on my production laptops.

Good luck!

[quote=134791:@Paulo Vargas]I’m having to update some parameters of my softwares to work well with Yosemite 10.10, what is the best way for me to check what version of OS X the program is open, explain:
When open my softwares one of the functions is to check the serial number of the computer, it is different in pre-Yosemite compared to Yosemite, as I say, if Yosemite do “it” does not do “That”, any help will be appreciated.
![/quote]

I have used Dave Sysemore’s method described at https://forum.xojo.com/2239-how-to-determine-os-which-version-and-which-ver-of-windoz and it does work very well.

I shall test it with Yosemite, but am sure it will be fine.

Hi Mike Cotrone,

Actually I know how to solve in Yosemite but I need to select the option depending on the version of the system, if in 10.9 use line 2 else if in 10.10 use line 18, this is what I need, ie identifying which version of OS you are using !

[quote=134816:@Paulo Vargas]Hi Mike Cotrone,

Actually I know how to solve in Yosemite but I need to select the option depending on the version of the system, if in 10.9 use line 2 else if in 10.10 use line 18, this is what I need, ie identifying which version of OS you are using ![/quote]

I understand. Could you Direct Mail me your line 18 information so I can see how to parse it?

Thanks!

Just use

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

… Or you can use That… :slight_smile: (Norman’s functions we all forgot about) :slight_smile:

[quote=134819:@Norman Palardy]Just use

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

That is what Dave method is based on, and as I write this under Yosemite, I verified it does work perfectly for what Paulo needs under Yosemite without the need for a shell and vagarious lines 2 and 18 :wink:

I will test and then I’ll return!

Thanks for the support and kindness of all of you.

Dave’s method uses sysv which is not recommended since it has issues with bug release numbers higher than 9

[quote=15562:@Dave S]Here is what I use

noerror=System.Gestalt("sysv",result) ///// <<<<<<<<< Bzzzzzztttttt [/quote]
Hence the 3 separate gestalts

The other alternative is to use MacOSLib NSProcessInfo.OperatingSystemVersionString
Not operating SystemName as this returns “NSMACHOperatingSystem”

[quote=134826:@Norman Palardy]Dave’s method uses sysv which is not recommended since it has issues with bug release numbers higher than 9

Hence the 3 separate gestalts

The other alternative is to use MacOSLib NSProcessInfo.OperatingSystemVersionString
Not operating SystemName as this returns “NSMACHOperatingSystem”[/quote]

Great. Seen Gestalt and did not notice your method was different. And the declare is interesting as well.

Updated code to support Maverics, Yosemite and Gestalts :slight_smile:

  Dim noerror As Boolean
  Dim result As Integer
  Dim sver As String
  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)
    
    sver=Hex(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 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

two things…

a) remove all references to sVer … I forgot to :frowning:
b) does not support identify of Win 8 or above…