Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / November 2007



Tip: Looking for answers? Try searching our database.

Detecting OS X version from perl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Cantrell - 14 Oct 2007 17:29 GMT
Is there any simple way that people can think of to detect which major
version of OS X my perl code is running on?

ie whether it's 10.0, 10.1 etc, I don't care about the difference
between 10.3.3 and 10.3.4.

Signature

David Cantrell | Hero of the Information Age

   I caught myself pulling grey hairs out of my beard.
   I'm definitely not going grey, but I am going vain.

Edward Moy - 14 Oct 2007 18:45 GMT
% perl -e 'chomp($vers = `sw_vers -productVersion`); print "$vers\n"'

That will get you either 10.x or 10.x.y.  You just need to strip off  
the .y if it is there.

Ed

> Is there any simple way that people can think of to detect which major
> version of OS X my perl code is running on?
>
> ie whether it's 10.0, 10.1 etc, I don't care about the difference
> between 10.3.3 and 10.3.4.
David Cantrell - 14 Oct 2007 23:56 GMT
> % perl -e 'chomp($vers = `sw_vers -productVersion`); print "$vers\n"'
> That will get you either 10.x or 10.x.y.  You just need to strip off  
> the .y if it is there.

Perfect, thanks!

Signature

David Cantrell | Nth greatest programmer in the world

"The whole aim of practical politics is to keep the populace alarmed
(and hence clamorous to be led to safety) by menacing it with an
endless series of hobgoblins, all of them imaginary"  -- H. L. Mencken

Chris Devers - 15 Oct 2007 02:37 GMT
>> % perl -e 'chomp($vers = `sw_vers -productVersion`); print "$vers\n"'
>> That will get you either 10.x or 10.x.y.  You just need to strip off
>> the .y if it is there.
>
> Perfect, thanks!

If for whatever reason that lets you down (e.g. trying to get the  
version of a host you have mounted via AFP / NFS / Samba / etc), you  
should also be able to poke in

/System/Library/CoreServices/SystemVersion.plist

which is basically the same info as sw_vers reports, but wrapped in XML.

Signature

Chris Devers

John Delacour - 14 Oct 2007 19:25 GMT
>Is there any simple way that people can think of to detect which major
>version of OS X my perl code is running on?
>
>ie whether it's 10.0, 10.1 etc, I don't care about the difference
>between 10.3.3 and 10.3.4.

print `osascript -e 'tell app "Finder" to version'`

JD
Chris Nandor - 16 Oct 2007 01:52 GMT
> Is there any simple way that people can think of to detect which major
> version of OS X my perl code is running on?
>
> ie whether it's 10.0, 10.1 etc, I don't care about the difference
> between 10.3.3 and 10.3.4.

This is nice in that it doesn't depend on external processes (sw_vers,
Finder) or files.

  use Mac::Gestalt qw(%Gestalt gestaltSystemVersion);
  (my $version = sprintf("%x", $Gestalt{gestaltSystemVersion()})) =~
     s/^(\d+)(\d)(\d)$/$1.$2.$3/;

Signature

Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Technology Group       pudge@ostg.com     http://ostg.com/

Eberhard Lisse - 17 Nov 2007 11:21 GMT
Very Cool,

on my iMini

Gestalt says it's 10.4.9
osascript/fider says 10.4.7
sw_version 10.4.11

the latter is correct :-)-O

on 10/16/07 2:52 AM Chris Nandor said the following:

>> Is there any simple way that people can think of to detect which major
>> version of OS X my perl code is running on?
[quoted text clipped - 8 lines]
>    (my $version = sprintf("%x", $Gestalt{gestaltSystemVersion()})) =~
>       s/^(\d+)(\d)(\d)$/$1.$2.$3/;

Signature

If you want to email me, replace nospam with el

Peter N Lewis - 18 Nov 2007 08:02 GMT
>  > ie whether it's 10.0, 10.1 etc, I don't care about the difference
>>  between 10.3.3 and 10.3.4.
[quoted text clipped - 5 lines]
>    (my $version = sprintf("%x", $Gestalt{gestaltSystemVersion()})) =~
>       s/^(\d+)(\d)(\d)$/$1.$2.$3/;

Note that gestaltSystemVersion tops out at ".9", so it will return
10.4.9 for all future 10.4 updates (including 10.4.10 and 10.4.11
etc).

Fortunately, this does not affect you.

You can use gestaltSystemVersionMajor, gestaltSystemVersionMinor, and
gestaltSystemVersionBugFix to return the three parts of the version
(10, 4 and 11).

Enjoy,
   Peter.

Signature

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>

Brian D Foy - 19 Nov 2007 03:22 GMT
> Is there any simple way that people can think of to detect which major
> version of OS X my perl code is running on?
>
> ie whether it's 10.0, 10.1 etc, I don't care about the difference
> between 10.3.3 and 10.3.4.

I was thinking about this last week because some of the stuff in
/usr/include changed between Panther and Tiger.

I've uploaded Mac::OSVersion, which I was working on at the same time
this thread came up. It has various methods to get the major, minor,
bugfix, build, and kernel numbers. It can also get those numbers
through various methods.

I've only tried in on Tiger so far, I'm trying to get my Panther
machine back up, and I haven't turned any work machines into Leopards
yet. Does anyone have something with Cheetah or Puma on it?

Does anyone have a matrix of Mac OS X version, build number, and kernel
versions? I'd like to have at least one method that just looks at a big
table.

I don't know how good this info is:

http://developer.apple.com/hardwaredrivers/download/usbdebug.html
http://en.wikipedia.org/wiki/Darwin_%28operating_system%29
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.