[SOLVED] Operating System Version String lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Shebuka · 2011-05-11 09:28 Hi all, is there an easy way to get a Mac OS X Version String, like one you see under Software voice in System Profiler (in my case 'Mac OS X 10.6.7 (10J869)' )? I'v found that i can create a TProcess and execute system_profiler SPSoftwareDataType but it' not really the easiest way... ---------------------------------------------------------------------- Phil · 2011-05-11 14:36 I'm sure there's a better way, but this works: 'Mac OS X 10.' + IntToStr(Lo(DosVersion) - 4) + '.' + IntToStr(Hi(DosVersion)); Does require the Dos unit, though. Thanks. -Phil ---------------------------------------------------------------------- marcov · 2011-05-12 07:23 Have a look had baseunix.fpuname ---------------------------------------------------------------------- Shebuka · 2011-06-30 13:47 If anyone need it, this one i made works fine Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ExtractOSVersionFromProfiler(): string;var  ProfProcess: TProcess;  path: string;  ProfStringList: TStringList;  NumRighe, i, HeaderStart, HeaderLength: integer;begin  Result := '';   path := 'sh -c "system_profiler SPSoftwareDataType"';  try    ProfProcess := Tprocess.Create(nil);    ProfProcess.CommandLine := path;    ProfProcess.Options := ProfProcess.Options + [poUsePipes, poWaitOnExit];    ProfProcess.Execute;  except    exit;  end;   try  ProfStringList := TStringList.Create;    ProfStringList.LoadFromStream(ProfProcess.Output);  except    exit;  end;   ProfProcess.Terminate(0);  FreeAndNil(ProfProcess);   NumRighe := ProfStringList.Count;   for i := 0 to NumRighe - 1 do  begin    HeaderStart := AnsiPos('System Version: ', ProfStringList.Strings[i]);    if HeaderStart > 0 then    begin      HeaderLength := Length('System Version: ');      Result := AnsiMidStr(ProfStringList.Strings[i], HeaderStart + HeaderLength, Length(ProfStringList.Strings[i]));      Break;    end;  end;   FreeAndNil(ProfStringList);end; ---------------------------------------------------------------------- IndianaJones · 2011-11-19 18:57 Here is another version. function ExtractOSVersionFromSW_Vers(Index: Byte): String; // Index 0: ProductName, 1: ProductVersion, 2: BuildVersion var   ProfProcess: TProcess;   path: string;   ProfStringList: TStringList;   Value: string; begin   Result := '';   path := 'sh -c "/usr/bin/sw_vers"';   try     ProfProcess := Tprocess.Create(nil);     ProfProcess.CommandLine := path;     ProfProcess.Options := ProfProcess.Options + [poUsePipes, poWaitOnExit];     ProfProcess.Execute;   except     exit;   end;   try     ProfStringList := TStringList.Create;     ProfStringList.LoadFromStream(ProfProcess.Output);   except     exit;   end;   ProfProcess.Terminate(0);   ProfStringList.NameValueSeparator:=':';   Result:=Trim(ProfstringList.ValueFromIndex[Index]);   FreeAndNil(ProfProcess);FreeAndNil(ProfStringList); end; ---------------------------------------------------------------------- jus · 2011-11-24 22:24 Ok, here is another version too. I've already posted this in the German Lazarus forum some times ago. I wrote a dylib-library. You can use the following 2 functions for free.    Code: [Select]GetMacOSVersion: function(): CFStringRef; cdecl; GetMacOSVersion2: function(var systemVersionMajor:SInt32; var systemVersionMinor: SInt32; var systemVersionBugFix:SInt32): CFStringRef; cdecl; GetMacOSVersion ... returns a localised os version string like "Version 10.6.7 (10J869)" GetMacOSVersion2 ... returns also the OS version info Major, Minor, Bugfix directly as integer values The following sample application contains only a TButton and a TMemo: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,   dynlibs, MacOSAll, CarbonProc; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Memo1: TMemo;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   H : TLibHandle;   GetMacOSVersion: function(): CFStringRef; cdecl;   GetMacOSVersion2: function(var systemVersionMajor:SInt32; var systemVersionMinor: SInt32; var systemVersionBugFix:SInt32): CFStringRef; cdecl; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var   cfs: CFStringRef;   s: String;   systemVersionMajor, systemVersionMinor, systemVersionBugFix: SInt32; begin   H := LoadLibrary('/Users/mac/Desktop/getosversion.dylib'); //<------ change here the directory path!!!   pointer(GetMacOSVersion) := GetProcedureAddress(H, 'GetMacOSVersion');   pointer(GetMacOSVersion2) := GetProcedureAddress(H, 'GetMacOSVersion2');   cfs:=GetMacOSVersion();   s:=CFStringToStr(cfs);   Memo1.Lines.Add('Mac Version (System): '+s);   cfs:=GetMacOSVersion2(systemVersionMajor, systemVersionMinor, systemVersionBugFix);   s:=CFStringToStr(cfs);   Memo1.Lines.Add('Mac Version (System): '+s);   Memo1.Lines.Add('Major: '+IntToStr(systemVersionMajor));   Memo1.Lines.Add('Minor: '+IntToStr(systemVersionMinor));   Memo1.Lines.Add('BugFix: '+IntToStr(systemVersionBugFix));   FreeLibrary(H); end; end. As shown above, the USES part should contain "dynlibs, MacOSAll, CarbonProc". If you want to use the sample source above directly, you must change the directory to your real directory in the line of LOADLIBRARY, where the "getosversion.dylib" is located on your harddisk. jus P.S.: Sorry for my bad english.