Created
March 20, 2012 23:43
-
-
Save acidprime/2142589 to your computer and use it in GitHub Desktop.
Get Display Serial Number as Extension Attribute - https://jamfnation.jamfsoftware.com/discussion.html?id=4081
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 | |
__author__ = 'Zack Smith @acidprime' | |
__version__ = '1.0' | |
import plistlib | |
import subprocess | |
system_profiler = '/usr/sbin/system_profiler' | |
spx_key = 'spdisplays_display-serial-number' | |
# Working on this to make it more generic | |
def genReport(): | |
spx = {} | |
# This is our key value schema | |
SPDisplaysDataType = { | |
spx_key : spx_key, | |
} | |
_dataTypes = { | |
'SPDisplaysDataType': SPDisplaysDataType, | |
} | |
dataTypes = _dataTypes.keys() | |
# run the system_profiler command with data types | |
arguments = [system_profiler,"-xml"] + dataTypes | |
getspx = subprocess.Popen(arguments, stdout=subprocess.PIPE) | |
spxOut, err = getspx.communicate() | |
rootObject = plistlib.readPlistFromString(spxOut) | |
# Parse datatype top level keys below | |
for array in rootObject: | |
for _dataType in _dataTypes: | |
if array['_dataType'] == _dataType: | |
_dataTypeSchema = _dataTypes[_dataType] | |
for key in _dataTypeSchema: | |
for item in array['_items']: | |
for spdisplays_ndrv in item['spdisplays_ndrvs']: | |
if spx_key in spdisplays_ndrv.keys(): | |
spx[spx_key] = spdisplays_ndrv[spx_key] | |
break | |
return spx | |
spx = genReport() | |
try: | |
print '<result>%s</result>' % spx[spx_key] | |
except KeyError: | |
print '<result></result>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment