Skip to content

Instantly share code, notes, and snippets.

@codeslinger
Created July 23, 2008 11:52
Show Gist options
  • Save codeslinger/1689 to your computer and use it in GitHub Desktop.
Save codeslinger/1689 to your computer and use it in GitHub Desktop.
Utility to give system info about a Mac
#!/usr/bin/env python
#
# Little command-line utility for telling you stuff about your Mac without
# having to click around all over the place. Originally found here and
# then cleaned up significantly: http://gist.github.com/1617
#
import sys
import commands
import plistlib
SYSTEM_KEYS = {
'machine_name': 'Machine Name',
'machine_model': 'Model',
'serial_number': 'Serial Number',
'physical_memory': 'Physical RAM',
'number_processors': 'Number of CPUs',
'current_processor_speed': 'CPU Speed',
'SMC_version': 'SMC Version',
'boot_rom_version': 'Boot ROM Version',
'l2_cache': 'L2 Cache',
# 'spdisplays_rom-revision': 'GPU ROM Version',
}
def main():
in_profile = commands.getstatusoutput('system_profiler -xml')
if len(in_profile) < 2:
sys.stderr.write("Error generating system profile!\n")
sys.exit(1)
parsed = plistlib.readPlistFromString(in_profile[1])
d = parsed[0].items()[5][1][0]
print '\n'.join(["%20s: %s" % (k, v)
for (k, v) in [(label, d[key])
for key, label in SYSTEM_KEYS.items()
if key in d]])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment