[Openmcl-devel] Determining OSX version at runtime

Paul Krueger plkrueger at comcast.net
Thu Aug 26 10:27:21 PDT 2010


As long as we're all contributing our personal hacks to do this, mine is:

(defun osx-version ()
  (let* ((info-str (with-output-to-string (str)
                     (run-program "sw_vers" nil :output str)))
         (search-str "ProductVersion:")
         (str-len (length search-str))
         (version-pos (search search-str info-str :test #'char=))
         (eol-pos (and version-pos 
                       (position #\linefeed info-str
                                 :test #'char=
                                 :start (+ version-pos str-len)))))
    (and version-pos (string-trim (list #\tab #\space)
                                  (subseq info-str (+ version-pos str-len) eol-pos)))))


? (osx-version)
"10.6.4"

but Gary's solution looks to be the most efficient to me. I wasn't previously aware of that version number correspondence.

Paul

On Aug 26, 2010, at 12:06 PM, Neil Baylis wrote:

> The Apple release notes for Snow Leopard suggest using NSAppKitVersionNumber.
> On my Snow Leopard system, I see
> 
> CL-USER> (apropos "NSAppKit")
> X86-DARWIN64::|NSAppKitVersionNumber|
> 
> But on my 32 bit ppc Leopard system, apropos doesn't know anything about it.
> 
> (Both systems using ccl 1.5)
> 
> Neil 
> 
> On Thu, Aug 26, 2010 at 9:39 AM, Raffael Cavallaro <raffaelcavallaro at mac.com> wrote:
> 
> On Aug 26, 2010, at 12:17 PM, Gary Palter wrote:
> 
> > Yes, you can use (software-version).  On Mac OS X, the first number is the major release + 4, the second number is the minor release, and the third number is usually zero.
> >
> > So, 9.8.0 is OS X 10.5.8 and 10.4.0  is OS X 10.6.4.
> 
> you can also cheat and get the product version directly (though this is not considered the correct method by apple):
> 
> ? (defun mac-os-x-version ()
>   (ccl::with-autorelease-pool
>       (let* ((plist
>               (#/dictionaryWithContentsOfFile: ns:ns-dictionary #@"/System/Library/CoreServices/SystemVersion.plist")))
>         (ccl::lisp-string-from-nsstring (#/valueForKey: plist #@"ProductVersion")))))
> 
> ? (mac-os-x-version)
> "10.6.4"
> 
> warmest regards,
> 
> Ralph
> 
> 
> Raffael Cavallaro
> raffaelcavallaro at me.com
> 
> 
> 
> 
> 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
> 
> 
> 
> -- 
> http://www.pixpopuli.com
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20100826/06208c5e/attachment.htm>


More information about the Openmcl-devel mailing list