OS Version under Monterey

I have a script that needs to do some GUI programming and I’m currently running it under 10.13, High Sierra. The GUI I’m referencing is the print dialog sheet in Safari. But they’re different references under High Sierra and Monterey, so I’m putting in an if test to check the version.

I used to use the shell command “sw_ver -productVersion” but that command isn’t found in the Monterey terminal under either zsh or bash. So I’m using this two-liner which reference the AppleScript system info:

set sysInfo to system info
set OSVersion to system version of sysInfo

However, under Monterey, I get “10.16” as the version number instead of the expected “12.3” shown in the version number when I pull down the “About this Mac” dialog under the Apple menu.

Why is the version number not “12.3”?

Is this the best way to get the system version number?

Jim. The following works for me on my Monterey computer:

set theVersion to (do shell script "sw_vers -productVersion") --> "12.3.1"

if the name of the utility has changed, perhaps this could be handled with a try statement.

try
	set theVersion to (do shell script "sw_ver -productVersion") -- works with older macOS
on error
	set theVersion to (do shell script "sw_vers -productVersion") -- works with newer macOS
end try

try this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"

set sysVer to (current application's NSProcessInfo's processInfo()'s operatingSystemVersionString())
set sysVer to (sysVer's stringByReplacingOccurrencesOfString:("Version") withString:"")
set sysVer to (sysVer's stringByReplacingOccurrencesOfString:("Build ") withString:"") as text

Or see if this works. (I don’t have Monterey currently installed, but when I did I believe this was working:

set OSVersion to get system version of (system info)

peavine,

That was what I originally tried (it’s how I’ve always gotten it in the past). Gave me an error command sw_ver not found. Tried it manually in Terminal- same thing.

Ed,

I did the system version of (system info) - comes back as 10.16, not the expected 12.3

When I get time time (I’ve got 2 computers doing Time Machine backups currently) , I’ll try the Objective-C version to see what it comes back as.

Thanks all.

The syntax I provided is slightly different than yours and that could make a difference.

I’d suggest restarting in safe mode, let it run or a few then restart in normal mode. That will clear all the cobwebs out of all the caches

Jim. That’s puzzling. I would expect the sw_ver utility to continue to work on older versions of macOS and the sw_vers utility to work on Monterey, as it does for me.

FWIW, the system info command returns the correct version number for me. I did a little Google research and macOS 10.16 was apparently an early beta release of Big Sur.

This gives me 12.4. I am running Monterey 12.4 Beta (21F5071b).

1 Like

My impression is that it was always “sw_vers -productVersion” with the ‘s’; not “sw_ver” which would return an error.

If you compile that script on Catalina 10.15 or earlier, Big Sur or later will always return “10.16.” This was done to protect older apps that aren’t aware of the new versioning starting with macOS 11, in case there was a chance they would break when the version number didn’t start with “10.”

You have to compile the script on Big Sur or Monterey for the script to return the right version number for current macOS versions. @JimBrandt, are you compiling it on High Sierra?

You are absolutely correct, and, typing it correctly, I get 12.3.1 on Monterey

I have changed over 150 scripts over the last week or so, trying to get all the Satimage OSAX out of them and my eyes are crosseyed.

Thanks for catching that.