OSVersion() for macOS Ventura/Sonoma/Sequoia

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

OSVersion() for macOS Ventura/Sonoma/Sequoia

Post by Quin »

Edit: This has now been implemented as of 6.12 B2


Hi,
macOS 15 (Sequoia) has recently been released. OSVersion() doesn't yet support it, though, with the latest it supports being #PB_OS_MacOSX_12 (released three years ago!). Can later OS detection support on Mac's possibly be added to the core?
Thanks!
Last edited by Quin on Fri Aug 16, 2024 3:07 pm, edited 2 times in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OSVersion() for macOS Ventura

Post by mk-soft »

Workaround ...

Code: Select all

;-TOP by mk-soft, Update 30.11.2024
; Link: https://www.purebasic.fr/english/viewtopic.php?t=80194

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  #PB_OS_MacOSX_13 = 13000
  #PB_OS_MacOSX_14 = 14000
  #PB_OS_MacOSX_15 = 15000
  
  Structure udtOSVersion
    majorVersion.i
    minorVersion.i
    patchVersion.i
  EndStructure
  
  Procedure MacOSVersion()
    Static NSVersion.udtOSVersion
    Protected Version, NSProcessInfo
    
    If Not NSVersion\majorVersion
      NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
      CocoaMessage(NSVersion, NSProcessInfo, "operatingSystemVersion")
    EndIf
    Version = NSVersion\majorVersion * 1000 + NSVersion\minorVersion * 10
    ProcedureReturn Version
  EndProcedure
  
  Procedure.s OSVersionString()
    Static NSVersion.udtOSVersion
    Protected Version.s, NSProcessInfo
    
    If Not NSVersion\majorVersion
      NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
      CocoaMessage(NSVersion, NSProcessInfo, "operatingSystemVersion")
    EndIf
    Version = "" +  NSVersion\majorVersion + "." + NSVersion\minorVersion + "." + NSVersion\patchVersion
    ProcedureReturn Version
  EndProcedure
  
  Macro OSVersion()
    MacOSVersion()
  EndMacro
CompilerEndIf

If OSVersion() >= #PB_OS_MacOSX_15
  MessageRequester("Info", "OS Version Sequoia " + OSVersionString())
ElseIf OSVersion() >= #PB_OS_MacOSX_14
  MessageRequester("Info", "OS Version Sonoma" + OSVersionString())
ElseIf OSVersion() >= #PB_OS_MacOSX_13
  MessageRequester("Info", "OS Version Ventura " + OSVersionString())
EndIf
Last edited by mk-soft on Sat Nov 30, 2024 12:04 pm, edited 2 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: OSVersion() for macOS Ventura

Post by Quin »

Amazing, thanks a lot for this! :) Would still love to see this make it into the stdlib, though
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: OSVersion() for macOS Ventura

Post by Quin »

With macOS Sonoma rapidly approaching public release, I'm going ahead and bumping this. Both Ventura and Sonoma constants would be great! :)
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: OSVersion() for macOS Ventura

Post by Quin »

Bumping once again. I now have an application that collects information about the OS a user is running, and it's incredibly unhelpful nowadays to just get Future for 13 and 14. This also seems like the sort of thing that 6.10 is after.
mrbungle
Enthusiast
Enthusiast
Posts: 149
Joined: Wed Dec 30, 2020 3:18 am

Re: OSVersion() for macOS Ventura

Post by mrbungle »

Reference: https://www.purebasic.fr/english/viewto ... on#p591872
Courtesy of mk-soft

Code: Select all

;-TOP my mk-soft, Update 28.11.2022

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  CompilerIf Not Defined(PB_OS_MacOSX_13, #PB_Constant)
    #PB_OS_MacOSX_13 = 13000
  
    Structure udtOSVersion
      majorVersion.i
      minorVersion.i
      patchVersion.i
    EndStructure
    
    Procedure MacOSVersion()
      Static NSVersion.udtOSVersion
      Protected Version, NSProcessInfo
      
      If Not NSVersion\majorVersion
        NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
        CocoaMessage(NSVersion, NSProcessInfo, "operatingSystemVersion")
      EndIf
      Version = NSVersion\majorVersion * 1000 + NSVersion\minorVersion * 10
      ProcedureReturn Version
    EndProcedure
    
    Macro OSVersion()
      MacOSVersion()
    EndMacro
  CompilerEndIf
CompilerEndIf

Debug OSVersion()

If OSVersion() >= #PB_OS_MacOSX_13
  MessageRequester("Info", "OS Version Ventura")
EndIf

Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: OSVersion() for macOS Ventura

Post by Quin »

What's the constant for Sonoma? I tried 14000 but that didn't seem to work.
mrbungle wrote: Mon Jan 15, 2024 10:32 pm Reference: https://www.purebasic.fr/english/viewto ... on#p591872
Courtesy of mk-soft

Code: Select all

;-TOP my mk-soft, Update 28.11.2022

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  CompilerIf Not Defined(PB_OS_MacOSX_13, #PB_Constant)
    #PB_OS_MacOSX_13 = 13000
  
    Structure udtOSVersion
      majorVersion.i
      minorVersion.i
      patchVersion.i
    EndStructure
    
    Procedure MacOSVersion()
      Static NSVersion.udtOSVersion
      Protected Version, NSProcessInfo
      
      If Not NSVersion\majorVersion
        NSProcessInfo = CocoaMessage(0, 0, "NSProcessInfo processInfo")
        CocoaMessage(NSVersion, NSProcessInfo, "operatingSystemVersion")
      EndIf
      Version = NSVersion\majorVersion * 1000 + NSVersion\minorVersion * 10
      ProcedureReturn Version
    EndProcedure
    
    Macro OSVersion()
      MacOSVersion()
    EndMacro
  CompilerEndIf
CompilerEndIf

Debug OSVersion()

If OSVersion() >= #PB_OS_MacOSX_13
  MessageRequester("Info", "OS Version Ventura")
EndIf

User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OSVersion() for macOS Ventura

Post by mk-soft »

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: OSVersion() for macOS Ventura

Post by Quin »

With macOS Sequoia dev beta 1, the following addition to mk-soft's script works nicely.

Code: Select all

#PB_OS_MacOSX_15 = 15000
Would love to see this in core though, it's quite out-of-date now...
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

re: [done] OSVersion() for macOS Ventura/Sonoma/Sequoia

Post by Quin »

Done as of 6.12 B2 :-)
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OSVersion() for macOS Ventura/Sonoma/Sequoia

Post by mk-soft »

Update 30.11.2024 on top ;)
OS Version Sequoia 15.1.1
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply