Get OS Version From Scripts
August 1st, 2009
It is sometimes useful to have a script check the OS version, for example the way to get the user’s full name was previously done using
niutil but Apple removed that command in Leopard (it can now be done using
One BSD command to read OS properties is
sysctl but prior to Leopard it didn’t offer
kern.osrelease making it a bit awkward, as you had to keep track of how
kern.osversion maps to a more humane number.
Lo and behold! Today I stumbled over
x-man-page links fail when there is an underscore in the URL, so type
man sw_vers in Terminal, rdar://7111174).
The manual page has no history, but the date is 2003 and an example in the manual page has
10.2.4 as output, so it goes way back.