m4lt3
m4lt3

Reputation: 465

Get all system information on OS X

Is there any class/function which gets me the whole system information object?

With system information object I mean all the data that we can see if we open the System Information app on OS X.

I have found a few classes so far, that gives me some information, but not all.

I fear there is no class which can give me all the information at once since I have not found anything in the documentation yet, but I might have overseen it since I am pretty new to OS X development and not yet familiar with the SDKs.

Upvotes: 1

Views: 950

Answers (1)

vadian
vadian

Reputation: 285200

Call system_profiler on NSTask

let task = NSTask()
let outputPipe = NSPipe()

task.launchPath = "/usr/sbin/system_profiler"
task.arguments = ["-xml", "-detailLevel", "mini"]
task.standardOutput = outputPipe
task.launch()
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()

let output = NSString(data: outputData, encoding: NSUTF8StringEncoding) as! String
print(output)

This syntax returns the minimum information as property list.
For further information like other detailLevel values see the man page

Upvotes: 3

Related Questions