in reply to Re^2: Get macOS Version
in thread Get macOS Version
"What is important is 16.7.0 and so on."
Are you sure about that? 16.7.0 (and darwin) refer to the Kernel Version:
[Note: I'm using Sierra 10.12.5.]
$ system_profiler SPSoftwareDataType Software: System Software Overview: System Version: macOS 10.12.5 (16F73) Kernel Version: Darwin 16.6.0 ...
It sounds like you really want the System Version. If so, and you only want the version number, this might be easier:
$ sw_vers -productVersion 10.12.5
To get at this information, you can use backticks, qx{}, open with '-|' mode, and other methods (the open doco has links to some of these). And, of course, add appropriate error handling.
Mac::OSVersion (already suggested by ++marto) uses both of those commands with backticks. It also provides a name() method; however, the names are hard-coded:
my @names = qw( Cheetah Puma Jaguar Panther Tiger Leopard ) ; push @names, 'Snow Leopard', 'Lion', 'Mountain Lion', 'Mavericks', 'Yosemite', 'El Capitan', 'Sierra', 'High Sierra', 'Mojave';
There's a potential problem with this. When Apple releases a new (named) version, that module will need to be updated, you'll need to upgrade to that updated version, and your users may need a similar upgrade.
If you wanted to handle the names yourself, https://support.apple.com/en-us/HT201260 has a list of names and version numbers. It looks like this information is kept up-to-date: it was last updated a month ago.
— Ken
|
---|