Recognize version of OS X

Below is the Apple recommend method if figuring out what version: This is not for display purposes, NSProcessInfo is for that.

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

Compare the double with the constant. So if you want to know if you’re running on 10.10, you would compare the return value with appKitVersionNumber10_10

Just like to add that this code was only possible thanks to Joe R, for teaching me how to access system constants.

[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]
I think we’ve discussed this before, Gestalt has been deprecated (still works, but for how long).

Starting with Yosemite, there is now a function on NSProcessInfo called “operatingSystemVersion” which returns a structure containing these values. Ironically, you need a method to detect if you’re running on 10.10 before you can figure out if you’re running on 10.10 :wink:

I wrapped up all the methods into a nice module.
http://www.ohanaware.com/xojo/OSXVersionInformation.zip

This module contains 3 functions:

  • appKitVersionNumber - for getting the version of the AppKit.
  • osVersionHumanReadable - for getting a display version of the OS version.
  • OSVersion - will return a structure contain the numbers broken down, ie.major, minor and bug.

Includes full source code.

Hafta love apple reporting the app kit version number as the means to map to what OS your on :stuck_out_tongue:
That just seems SO wrong

I forgot to add, that the OSVersion function uses the correct method of getting all 3 places on Yosemite and then reverts back to Gestalt on 10.9 or lower.

[quote=134860:@Sam Rowlands]I think we’ve discussed this before, Gestalt has been deprecated (still works, but for how long).
[/quote]
True - deprecated as of 10.8 so its on life support and Apple seems to be more aggressive about removing things
Usually they have / had been waiting til there was a decent replacement in wide usage (NSProcessInfo) and then they’ll remove things
The AppKitVersion number is really a round about way

Seems from the release note that Apple suggests you do something like (see https://developer.apple.com/Library/mac/releasenotes/AppKit/RN-AppKit/index.html)

[code] const appKitVersionNumber10_7 = 1138
Const appKitVersionNumber10_8 = 1187
Const appKitVersionNumber10_9 = 1265
Const appKitVersionNumber10_10 = 1328

if (appKitVersionNumber <= appKitVersionNumber10_7)
/ / On a 10.7.x or earlier system
elseif (appKitVersionNumber <= appKitVersionNumber10_8)
// On a 10.8 - 10.8.x system
elseif (appKitVersionNumber <= appKitVersionNumber10_9)
// 10.9
elseif (appKitVersionNumber <= appKitVersionNumber10_10)
// 10.10
end if[/code]

Tanks Guys for All Support !

Guys, what do you think of the capture OS X Version with Applescript?

The code below is also possible:

set os_version to do shell script "sw_vers -productVersion"

or this:

tell application "Finder" set os_version to version end tell

The opinion of you is very important to my final decision.

Won’t work if you intend to distribute via the App Store.

If there is an API for doing something, unless the API is broken, use the API.

[quote=134887:@Sam Rowlands]Won’t work if you intend to distribute via the App Store.

If there is an API for doing something, unless the API is broken, use the API.[/quote]

Hi Sam,

I have no intention of distributing Apps for AppleStore, my segment is aimed at companies that already got it today and using my solutions for process automation on graphical area, a very small segment installed directly on the machines for me .

System.Gestalt is deprecated.

I get the system version by looking at the file
volume/System/Library/CoreServices/SystemInfo.plist

but dont know if it’s still possible from an accepted macapp store application ?

[quote=134908:@jean-yves pochez]I get the system version by looking at the file
volume/System/Library/CoreServices/SystemInfo.plist

but dont know if it’s still possible from an accepted macapp store application ?[/quote]
As Apple have provided approved ways of getting the version number (which the code I provided above uses), I wouldn’t suggest doing it any other way. Apple have a habit of blocking off ways to do things that they don’t approve of.

This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?

[quote=134948:@Paulo Vargas]This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?[/quote]

The issue is mostly for the Apple Store. At the moment, there is no indication that non-MAS apps will not be able to use AppleScript.

[quote=134948:@Paulo Vargas]This is true Sam, but you think Apple would block via Applescript in the near future ?
Starting Apple i share nothing but I find it hard to be a native technique and system that already works for years, what you think ?[/quote]
If you’re asking for my opinion, it would be to use the API. This is how Objective-C & Swift apps get this information and that’s all Apple really cares about.

As for something that’s worked for years and suddenly gets broken, it does happen. See my thread on the removal of NSSharingService for 32-Bit applications.

Apple Script is a funny thing, it’s very useful, but it can’t really be used from a Sandboxed application (which of course is required for MAS).

Ultimately it’s up to you how you do it, APIs are the most reliable way and should be the most future proof, but if you want to use Apple Script, dig into system packages and extract information, it works now, for how long, only the engineers at Apple know.

[quote=135011:@Sam Rowlands]If you’re asking for my opinion, it would be to use the API. This is how Objective-C & Swift apps get this information and that’s all Apple really cares about.

As for something that’s worked for years and suddenly gets broken, it does happen. See my thread on the removal of NSSharingService for 32-Bit applications.

Apple Script is a funny thing, it’s very useful, but it can’t really be used from a Sandboxed application (which of course is required for MAS).

Ultimately it’s up to you how you do it, APIs are the most reliable way and should be the most future proof, but if you want to use Apple Script, dig into system packages and extract information, it works now, for how long, only the engineers at Apple know.[/quote]

Yes agree with You and Michel, but I think this time I will still use AppleScripts for if by chance AppleScripts are depreciated I do not really know how I’m gonna get because I have lots of functions for interacting with the Adobe software package that simply would not be accessible and hence capture the version of the OS is the least worry.

Unless Adobe starts providing another API, AppleScript seems the only game in town for automation.

Yes my friend Michel, I even studied and still studying these possibilities but without AppleScripts them interact with the software to generate a plugin or something is a very complicated task, but it is up there as well in some limited functions and as my area is graphical I am without many options.