Getting basic machine info under OS X

450 views Asked by At

I've written a very short program to collect some log files spit out by a 3rd party application. It zips up the files and emails them to me.

I'd also like to collect some information about the machine, and especially its graphics capabilities. Basically I'd like two pages from System Report, Hardware and Graphics/Displays. Gestalt is gone, so I'm looking for other solutions.

I found a solution here on SO to get the model of the machine using sysctlbyname, but it seems the values here are quite limited.

So, does anyone have a simple way to get GPU information?

2

There are 2 answers

1
Maury Markowitz On BEST ANSWER

Following on Mark's answer above, here's how to do it in (Swift) code. First, I used this solution to run a shell command:

func shell(launchPath: String, arguments: [String]) -> String
{
    let task = NSTask()
    task.launchPath = launchPath
    task.arguments = arguments

    let pipe = NSPipe()
    task.standardOutput = pipe
    task.launch()

    let data = pipe.fileHandleForReading.readDataToEndOfFile()
    let output: String = NSString(data: data, encoding: NSUTF8StringEncoding)! as String

    return output
}

Then after a bit of playing around in system_profiler, I found I was interested in two keys, SPHardwareDataType and SPDisplaysDataType. That left me wondering where system_profiler is located, but which system_profiler solved that. So I finally got what I needed thus:

let ai = shell("/usr/sbin/system_profiler", arguments: ["SPHardwareDataType", "SPDisplaysDataType"])

The results are a formatted string that is pretty much good-to-go as it is.

3
Mark Setchell On

Using System Profiler from the commandline in Terminal, or executing it as NSTask:

/usr/sbin/system_profiler | awk '/^Graphics/{p=1;print;next} /^[A-Z]/{p=0} p'

Output

Graphics/Displays: 

AMD Radeon R9 M395:

  Chipset Model: AMD Radeon R9 M395
  Type: GPU
  Bus: PCIe
  PCIe Lane Width: x16
  VRAM (Total): 2048 MB
  Vendor: ATI (0x1002)
  Device ID: 0x6920
  Revision ID: 0x0001
  ROM Revision: 113-C905AA-799
  EFI Driver Version: 01.00.799
  Displays:
    iMac:
      Display Type: Retina LCD
      Resolution: 5120 x 2880 Retina
      Retina: Yes
      Pixel Depth: 30-Bit Color (ARGB2101010)
      Main Display: Yes
      Mirror: Off
      Online: Yes
      Built-In: Yes