Mac GeekeryGet your geek on. |
|
blog advertising is good for you
recent popular content
User login
|
Mac OS X stores the current marketing OS version (i.e. not the kernel revision number) in a property list in GrepYou could to use grep -A1 ProductVersion /System/Library/CoreServices/SystemVersion.plist sw_versAs noted in the comments, you can get an even cleaner version with the sw_vers -productVersion system_profilerAlso as noted in the comments, you can get more detailed results with System Profiler. However they’re not as script-friendly as the system_profiler SPSoftwareDataType
About Adam Knight
Author Biography Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c. In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon. Bug him over AIM or email [link fixed]. |
Why wouldn’t you just use ‘sw_vers’ ?
Why not use defaults, which will even work on binary .plists?
defaults read /System/Library/CoreServices/SystemVersion ProductVersion
It can also be achieved using the system_profiler command…
system_profiler -detailLevel mini | grep “System Version”
Your command brings back two lines of XML on my machine:
<key>ProductVersion</key> <string>10.4.5</string>An alternative approach might be the command:
which produces the slightly cleaner result:
System Version: Mac OS X 10.4.5 (8H14)Each approach would require a little bit more processing (perhaps awk) to strip out the surrounding text if you wanted to test against the result in a script. If you want an easier version of the command, it can be simplified to the following, although it will then run slightly slower (about one to two seconds on my machine, against almost instantaneous for the first version):
Or you could just use ‘sw_vers‘, which has been in OSX forever now, and does the work of parsing that file even more simply than grep does
system_profiler is a great way to get command-line information. Without parameters it prints out a wealth of information. But you can limit it as follows to see just the system software version.
Better yet, use system_profiler.
$ system_profiler SPSoftwareDataType Software: System Software Overview: System Version: Mac OS X 10.4.9 (8P135) Kernel Version: Darwin 8.9.0 Boot Volume: Macintosh HD Computer Name: hostname User Name: Your Name (your_user)It’s probably better to use ‘sw_vers’ for this (as it’s likely to exist across Mac OS X revisions whereas that particular plist may cease to exist in the future).
% sw_vers
ProductName: Mac OS X
ProductVersion: 10.4.9
BuildVersion: 8P135
Because
sw_vers -productVersionis too easy?Because I hadn’t come across that command and it was easier to parse out the plist data than the system_profiler data when I needed to use this.
That, however, works.
How does one find out if the computer is Intel or not? I need to find out if the Mac is running Rosetta.
Use the
machineor uname -p commands to get the processor type.Use the arch command to test for PPC/intel. It outputs either “ppc” or “i386”.
—DH
uname -r
Kernel version. This gives you the marketing version.
This works in Mac OS X, Red Hat Fedora Core and Ubuntu:
sysctl kern.osrelease