Created
January 4, 2017 16:43
-
-
Save pudquick/83ec0ce0a5f3dbc52e70c8c1ce64a389 to your computer and use it in GitHub Desktop.
Extract serial number out of .spx files generated by System Profiler on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import plistlib, sys | |
# Grab the path to the spx file | |
file_path = sys.argv[1] | |
# ingest the spx (which is a plist) | |
file_data = plistlib.readPlist(file_path) | |
# find the item within it that has the following values: | |
# _parentDataType: SPRootDataType | |
# _dataType: SPHardwareDataType | |
candidates = [] | |
for x in file_data: | |
if x.get('_parentDataType', None) == 'SPRootDataType': | |
if x.get('_dataType', None) == 'SPHardwareDataType': | |
candidates.append(x) | |
# Only emit a serial if we have one | |
for x in candidates: | |
try: | |
print x['_items'][0]['serial_number'] | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is a super useful script.
Can you add a few more lines so that one can return information such as hard drive size etc?
I've tried this but am getting no success...
candidates2 =[]
for y in file_data:
if y.get('_parentDataType', None) == 'SPRootDataType':
if x.get('_dataType', None) == 'SPSerialATADataType':()
candidates2.append(y)
for y in candidates2:
print y['_items'][0]['size_in_bytes']
Thanks.