Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created March 20, 2012 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidprime/2142589 to your computer and use it in GitHub Desktop.
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
#!/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