Test OS version - Yosemite or later?

I’ve been using this method of testing the OS version, but it doesn’t work for versions 10.10 or later, apparently.

set sysvers to ((system attribute "sysv") mod 4096 div 16)

What method should be used to test whether the version is 10.10 or later??

Hi.

Since 10.4.10, there have been “sys1”, “sys2”, and “sys3” attributes which return the three parts of the system version:

set sysvers to {system attribute "sys1", system attribute "sys2", system attribute "sys3"}

However, I believe these too are now deprecated, although it doesn’t say so in the StandardAdditions dictionary. Nowadays there’s another StandardAdditions method:

set sysvers to system version of (system info)

The result is text, but it can be compared using ‘considering numeric strings’, eg.:

set sysvers to system version of (system info)

considering numeric strings
	set sysVerOK to (sysvers ≥ "10.9")
end considering

Alternatively use the Foundation framework

use framework "Foundation"
set processInfo to current application's NSProcessInfo's processInfo()'s operatingSystemVersion() as record
set isYosemiteAndHigher to processInfo's majorVersion > 9

operatingSystemVersion() is a record containing majorVersion, minorVersion and patchVersion corresponding to sys1 to sys3

It’s a nice idea, but unfortunately operatingSystemVersion() returns a struct that’s only bridged to AppleScript in 10.11. And if you’re running that, you probably don’t need to ask the question :wink:

i used always to ask the system info, like Mr. Garvey suggested (thanks for all your contributions)

set sysvers to system version of (system info)

a yet cheaper method is to ask the finder for the installed OS. Why complicate things? :stuck_out_tongue: (ok, the call depends on the finder, but is a small thing)

tell application "Finder" to set vv to version

Hello Nigel
It seems that your test doesn’t fit the original requirements.

set sysvers to system version of (system info)
set sysvers to "10.9.5" # Here for tests only because I'm running 10.11.5
considering numeric strings
	set sysVerOK to (sysvers ≥ "10.9")
end considering
--> true

Would need this one :

set sysvers to system version of (system info)
set sysvers to "10.9.5" # Here for tests only because I'm running 10.11.5
considering numeric strings
	set sysVerOK to (sysvers is not less than "10.10")
end considering
--> false

The day sys1, sys2 and sys3 would be deprecated we would be able to use :

set sysvers to system version of (system info)

set {sys1, sys2, sys3} to my decoupe(sysvers, ".")

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) samedi 2 juillet 2016 12:29:53

Many thanks for these. Yvan’s brief script works perfectly.

Hi Joy.

The Finder version isn’t always the same as the system version ” as at present, in fact, where the current system version is 10.11.5 and the current Finder version 10.11.4. But they’re only likely to differ with respect to the update (third) element.

Hi Yvan.

I chose “10.9” for the comparison simply to show that “11” is greater than “9” when considering numeric strings. It was relevant to the point I was making about being able to compare version texts directly.