How to programmatically detect Mac OS X Server Edition?
Is anybody knows any API that can help to distinguish Mac OS X "Server edition" from "Desktop edition"? My application should know on which edition of Mac OS X it currently running. 开发者_高级运维(Server or Desktop)
sw_vers
appears to do it by checking /System/Library/CoreServices/ServerVersion.plist -- you could probably get by with just seeing if the file exists.
If there is a real reason why your application needs to know this, I'd recommend checking for the existence of the component that makes the difference on desktop/server. For example, if the server version comes with the program or library foo
and the desktop version doesn't, and you would like to use foo
, then check for the existence (and/or version of) foo
instead of trying to infer it from Server vs Desktop OS.
(Meanwhile, one possible starting point to check the OS version are the commands sw_vers
and system_profiler SPSoftwareDataType
.)
Maybe you can find a difference using the sysctl API, or Gestalt
精彩评论