Skip to content

Instantly share code, notes, and snippets.

@carlashley
Created December 21, 2016 03:39
Show Gist options
  • Save carlashley/927a9fd6b1d03081f311bde017170d3e to your computer and use it in GitHub Desktop.
Save carlashley/927a9fd6b1d03081f311bde017170d3e to your computer and use it in GitHub Desktop.
Mac Hardware Info
#!/usr/bin/python
# Use system_profiler output in XML to get information about Mac hardware
import plistlib
import subprocess
cmd = ['system_profiler', '-xml', 'SPHardwareDataType']
(results, error) = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
hardware = plistlib.readPlistFromString(results)[0]['_items'][0]
serial_no = hardware['serial_number']
platform_uuid = hardware['platform_UUID']
machine_model = hardware['machine_model']
print serial_no
print platform_uuid
print machine_model
print 'Available keys: %s' % hardware.keys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment