Detect Mac OS X Version

F

Filipe

After Googling for a while I couldn't find a way of detecting the Mac
OS X version ruby is running on. I tryed the RUBY_PLATFORM constant
but it only tells me I'm running Mac OS, not its version.

Is there any other way of detecting wether the script is beeing run on
10.4 or 10.5?

Thanks :)
 
B

Benjamin Reed

After Googling for a while I couldn't find a way of detecting the Mac
OS X version ruby is running on. I tryed the RUBY_PLATFORM constant
but it only tells me I'm running Mac OS, not its version.

Is there any other way of detecting wether the script is beeing run on
10.4 or 10.5?

you can always run "sw_vers -productVersion" as a system command...
 
L

Lyle Johnson

After Googling for a while I couldn't find a way of detecting the Mac
OS X version ruby is running on. I tryed the RUBY_PLATFORM constant
but it only tells me I'm running Mac OS, not its version.

Is there any other way of detecting wether the script is beeing run on
10.4 or 10.5?

The uname command returns the Darwin OS version, where Mac OS 10.4 is
Darwin 8.x and Mac OS 10.5 is Darwin 9.x, so this should work:

os_version = `uname -r`
if os_version =~ /^8/
# Tiger
elsif os_version =~ /^9/
# Leopard
end

Hope this helps,

Lyle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top