cli the OS version?

mosx86

Registered
I'm working on a shell script and need to be able to pull the OS version and the version of Safari in order to do various things...

I can get Safari's version number from the

/Applications/Safari.app/Contents/version.plist file and with some creative sed should be able to finagle just the version number.

For the OS version, using will get me close enough to manipulate:

system_profiler SPSoftwareDataType |grep "System Version"

But I was curious if there was a more obvious and simpler way to do this from the command line.

Thanks!
 
So there are a plethora of ways all better than what I was doing:

Code:
system_profiler -xml SPSoftwareDataType | awk '/os_version/{getline;print $4}'

How to get the version of Mac OS X from the CLI

It seems the less complicated way is:

Code:
sw_vers -productVersion

or

Code:
defaults read /System/Library/CoreServices/SystemVersion ProductVersion

Now to figure out a less complicated way to find the Safari version than what I was using:

Code:
cat /Applications/Safari.app/Contents/version.plist | awk '/CFBundleShortVersionString/{getline;print $1}' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'

Defaults can read plist files so lets try this:

Code:
defaults read /Applications/Safari.app/Contents/version CFBundleShortVersionString

Success (but only if you use the full path)!!!
 
$ sysctl -n kern.osversion

But, the version it gives is a hexnumber: 9C7010 (same as your version has in parentheses), so I am not sure if it helps.
 
Back
Top