-
Notifications
You must be signed in to change notification settings - Fork 5
/
attached_displays.py
executable file
·123 lines (100 loc) · 4.25 KB
/
attached_displays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python
"""
This should not be blank.
"""
# Copyright (c) 2017 University of Utah Student Computing Labs. ################
# All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appears in all copies and
# that both that copyright notice and this permission notice appear
# in supporting documentation, and that the name of The University
# of Utah not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission. This software is supplied as is without expressed or
# implied warranties of any kind.
################################################################################
# attached_displays.py #########################################################
#
# A Python script/Jamf Pro Extension Attribute to inventory and report on
# attached displays.
#
# 1.0.0 2017.09.08 Initial release. tjm
#
################################################################################
# Notes ########################################################################
#
# The output is set up to split three times. Once on ':' will give you the count
# of displays and the description string. And then splitting the description
# string on ':' will give you individual displays. Finally on ',' will give
# features. You can also split the resolution if you need to, for height,
# width, etc.
#
# 2: iMac, Built-in, Retina, 2560 x 1440 (5120 x 2880); ASUS VH236H, Primary, 1920 x 1080 @ 60 Hz (1920 x 1080)
# ^ ^
# | 1. split on ':" |
# | 2. split on ';'
# Continue spliting on ',' for indiviual features
# Current resolution is displayed, Maximum resolution available in parentheses
#
################################################################################
from __future__ import print_function
import subprocess
import plistlib
def main():
"""
This should not be blank.
"""
count_displays = 0
master_string = ""
raw_displays = subprocess.check_output(["system_profiler", "SPDisplaysDataType", "-xml"])
plist_displays = plistlib.readPlistFromString(raw_displays)
list_of_displays = plist_displays[0]['_items']
for item in list_of_displays:
sublist = item['spdisplays_ndrvs']
count_displays = str(len(sublist))
for subitem in sublist:
feature_list = []
try:
name_string = subitem['_name']
except:
name_string = ""
# Build list of resolution strings
try:
resolution_string = subitem['_spdisplays_resolution']
except:
resolution_string = ""
try:
resolution_string = resolution_string + " (" + subitem['_spdisplays_pixels'] + ")"
except:
resolution_string = resolution_string + ""
# Build list of individual features
try:
display_type = subitem['spdisplays_display_type']
except:
display_type = ""
try:
display_main_raw = subitem['spdisplays_main']
if 'yes' in display_main_raw:
feature_list.append("Primary")
except:
pass
if 'built' in display_type:
feature_list.append("Built-in")
if 'retina' in display_type:
feature_list.append("Retina")
if 'spdisplays_on' in subitem['spdisplays_mirror']:
feature_list.append("Mirrored")
if feature_list:
output_string = name_string + ", " + ", ".join(feature_list) + ", " + resolution_string
else:
output_string = name_string + ", " + resolution_string
if master_string:
master_string = master_string + "; " + output_string
else:
master_string = output_string
master_string = count_displays + ": " + master_string
print("<result>" + master_string + "</result>")
if __name__ == '__main__':
main()