List Connected Display type

sardesm
Contributor

Anyone have a script or extension attribute to pull this info, I am looking for the type of display connected i.e. Cinema, thunderbolt, other?

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

OK, try this. system_profiler isn't the easiest thing to scrape data from so I don't know for sure if this will work, but it does on my test system that has an old lenovo external display hooked up to it. I'll have to see if this would work in a case where there is both an Apple display and a non Apple display as well as the built in display all connected at the same time.

#!/bin/sh

displays=$(system_profiler SPDisplaysDataType -xml | grep -A2 "</data>" | awk -F'>|<' '/_name/{getline; print $3}')

echo "<result>$displays</result>"

Curious to hear how that works.

View solution in original post

21 REPLIES 21

mm2270
Legendary Contributor III

What information exactly are you looking for? Would something that just shows data like:

Color LCD
Thunderbolt Display

be enough? That was run from my MacBook Pro, showing both the built in display and an external Thunderbolt Display.
Or were you looking only for external displays or possibly more information on each display?

sardesm
Contributor

Cinema Display
Thunderbolt Display
Color LCD

Pretty much looking for external display type as we have to purchase vesa mounts for them.

mm2270
Legendary Contributor III

OK, try this to see if it lists what you're looking for. Still not clear if you only need the overall display type or more specific information.

#!/bin/sh

displays=$(system_profiler SPDisplaysDataType | awk '/Display Type:/{print x}; {x=$0}' | sed -e 's/^ *//g;s/://g')

echo "<result>$displays</result>"

sardesm
Contributor

So i got this result, which mostly helps but i know this user has another display connected that displays in system profiler.

Authenticating...
Successfully authenticated.
Verifying Computer's Identity...
The MAC Address has been verified.
Checking Operating System Version...
Running Mac OS X 10.7.5 (11G63b)
Verifying /usr/sbin/jamf...
/usr/sbin/jamf is current (9.72)
Verifying /Library/Preferences/com.jamfsoftware.jamf.plist...
Preparing Policy...
Running script list display type...
Script exit code: 0
Script result: LED Cinema Display

sardesm
Contributor

Other display is a non apple display but it does display in system profiler.

mm2270
Legendary Contributor III

Is it possible to post what the System Profiler reports looks like from that Mac if you run this on it?
system_profiler SPDisplaysDataType

That might help figure out why its not being picked up. Its possible it just shows up differently in that output.

Edit: Actually never mind. I see why its not showing up. Non Apple displays don't have a Display Type line below the name of the display. Hmm. Might be tricky to get that info into the result. I'll see what I can come up with. I have a funny feeling this may be easier in something other than bash.

sardesm
Contributor

$ system_profiler SPDisplaysDataType
Graphics/Displays:

ATI Radeon HD 5770:

Chipset Model: ATI Radeon HD 5770 Type: GPU Bus: PCIe Slot: Slot-1 PCIe Lane Width: x16 VRAM (Total): 1024 MB Vendor: ATI (0x1002) Device ID: 0x68b8 Revision ID: 0x0000 ROM Revision: 113-C0160C-155 EFI Driver Version: 01.00.436

sardesm
Contributor

First result is from sshing into his machine here is the result from his machine . I am on 10.10.3 user is on 10.7.5

ATI Radeon HD 5770:

Chipset Model: ATI Radeon HD 5770 Type: GPU Bus: PCIe Slot: Slot-1 PCIe Lane Width: x16 VRAM (Total): 1024 MB Vendor: ATI (0x1002) Device ID: 0x68b8 Revision ID: 0x0000 ROM Revision: 113-C0160C-155 EFI Driver Version: 01.00.436 Displays: LED Cinema Display: Display Type: LCD Resolution: 2560 x 1440 Pixel Depth: 32-Bit Color (ARGB8888) Display Serial Number: W820413D6JL Main Display: Yes Mirror: Off Online: Yes Rotation: Supported Connection Type: DisplayPort PX2710MW: Resolution: 1920 x 1080 @ 60 Hz Pixel Depth: 32-Bit Color (ARGB8888) Mirror: Off Online: Yes Rotation: Supported

sardesm
Contributor

As you can see it lists 2 displays

LED Cinema Display
DisplayPort PX2710MW

mm2270
Legendary Contributor III

OK, try this. system_profiler isn't the easiest thing to scrape data from so I don't know for sure if this will work, but it does on my test system that has an old lenovo external display hooked up to it. I'll have to see if this would work in a case where there is both an Apple display and a non Apple display as well as the built in display all connected at the same time.

#!/bin/sh

displays=$(system_profiler SPDisplaysDataType -xml | grep -A2 "</data>" | awk -F'>|<' '/_name/{getline; print $3}')

echo "<result>$displays</result>"

Curious to hear how that works.

sardesm
Contributor

no dice

Authenticating...
Successfully authenticated.
Verifying Computer's Identity...
The MAC Address has been verified.
Checking Operating System Version...
Running Mac OS X 10.7.5 (11G63b)
Verifying /usr/sbin/jamf...
/usr/sbin/jamf is current (9.72)
Verifying /Library/Preferences/com.jamfsoftware.jamf.plist...
Preparing Policy...

Running script find display type 2...
Script exit code: 0
Script result: spdisplays_displayport_info

mm2270
Legendary Contributor III

Might be because the Mac is on 10.7.5. I had tested it on a Mac running 10.10.3 and mine running 10.9.5, and it showed all displays connected in both cases. Any chance you can test it on a more current OS X version? Its hard to support OS X going back to 10.7.x at this point as I don't even have anything nearby running that which I can test against.

Edit: Running the above script on my 10.9.5 Mac with 2 externals connected, results are:

<result>Color LCD
Thunderbolt Display
LT1952p Wide</result>

So its working for me. As I said, I don't know if there's some difference with 10.7 that is causing it not to work, but its possible. I can barely remember how things work on that version of OS X at this point.

sardesm
Contributor

Works on 10.10, 10.9 not 10.8 or below.

Unfortunately i inherited a mixed environment that i am working on getting up to the same standards.

mm2270
Legendary Contributor III

So one last effort to help you out. From a 10.7.or 10.8 Mac can you run the following in Terminal and post the output?

system_profiler SPDisplaysDataType -xml

Since that's what the script is using - output from System Profiler in xml format, it may show what needs to happen for those older OSes to pull the right information. No promises though since it may not lend itself to grabbing that data so easily.

Edit: I managed to locate a 10.8 Mac in Casper here that I remoted into and ran the system_profiler command on. The displays information it shows is extremely minimal, so I think that's why its not working on those older OSes. Apparently Apple beefed up what system profiler shows from 10.9 and up. There's really not much you can pull from the older OSes it seems.

sardesm
Contributor

system_profiler SPDisplaysDataType -xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>_SPCommandLineArguments</key>
<array>
<string>/usr/sbin/system_profiler</string>
<string>SPDisplaysDataType</string>
<string>-xml</string>
</array>
<key>_SPCompletionInterval</key>
<real>0.18423604965209961</real>
<key>_dataType</key>
<string>SPDisplaysDataType</string>
<key>_detailLevel</key>
<integer>-1</integer>
<key>_items</key>
<array>
<dict>
<key>_name</key>
<string>kHW_NVidiaGeForceGTX675MXItem</string>
<key>spdisplays_device-id</key>
<string>0x11a2</string>
<key>spdisplays_ndrvs</key>
<array>
<dict>
<key>_name</key>
<string>iMac</string>
<key>_spdisplays_display-product-id</key>
<string>b005</string>
<key>_spdisplays_display-vendor-id</key>
<string>610</string>
<key>_spdisplays_display-week</key>
<string>28</string>
<key>_spdisplays_display-year</key>
<string>2012</string>
<key>_spdisplays_displayport_device</key>
<dict>
<key>_dpcd-registers</key>
<data>
EQqEAQEAAYACAQQBDwAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAqEAAAAAAAQAAgAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AABBAHd3AQEAAAAAAAAA
AAAAAIAAgACAAIAACgAA
AAAAAAQAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAA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AAAAAA
AAAAAAAAAAAAAAAAAAAA
</data>
<key>_name</key>
<string>spdisplays_displayport_info</string>
<key>spdisplays_displayport_DPCD_version</key>
<string>1.1</string>
<key>spdisplays_displayport_current_bandwidth</key>
<string> 2.70 Gbps</string>
<key>spdisplays_displayport_current_lanes</key>
<string>4</string>
<key>spdisplays_displayport_current_spread</key>
<string>&lt;= 0.5%</string>
<key>spdisplays_displayport_hdcp_capability</key>
<string>spdisplays_displayport_hdcp_capable</string>
<key>spdisplays_displayport_max_bandwidth</key>
<string> 2.70 Gbps</string>
<key>spdisplays_displayport_max_lanes</key>
<string>4</string>
<key>spdisplays_displayport_max_spread</key>
<string>0.5%</string>
<key>spdisplays_displayport_sink_ascii_name</key>
<string>MN27d3</string>
<key>spdisplays_displayport_sink_chip_version</key>
<string> 1.02</string>
<key>spdisplays_displayport_sink_count</key>
<string>1</string>
<key>spdisplays_displayport_sink_sw_version</key>
<string> 5</string>
<key>spdisplays_displayport_sink_vendor</key>
<string>00 10 fa</string>
</dict>
<key>_spdisplays_edid</key>
<string>0x00ffffffffffff00061005b0000000001c160104b53c2278226fb1a7554c9e250c505400000001010101010101010101010101010101565e00a0a0a029503020350055502100001a1a1d008051d01c204080350055502100001c000000fc00694d61630a2020202020202020000000000000000000000000000000000000018e020328c1230907078301000070fa100000127a31fc78bdb202108874e56afa1000dbeef5f7f8feff565e00a0a0a029503020350055502100001a1a1d008051d01c204080350055502100001c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cc</string>
<key>_spdisplays_pixels</key>
<string>2560 x 1440</string>
<key>spdisplays_builtin</key>
<string>spdisplays_yes</string>
<key>spdisplays_connection_type</key>
<string>spdisplays_displayport_dongletype_dp</string>
<key>spdisplays_depth</key>
<string>CGSThirtytwoBitColor</string>
<key>spdisplays_display_type</key>
<string>spdisplays_LCD</string>
<key>spdisplays_main</key>
<string>spdisplays_yes</string>
<key>spdisplays_mirror</key>
<string>spdisplays_off</string>
<key>spdisplays_online</key>
<string>spdisplays_yes</string>
<key>spdisplays_resolution</key>
<string>2560 x 1440</string>
</dict>
</array>
<key>spdisplays_pcie_width</key>
<string>x16</string>
<key>spdisplays_revision-id</key>
<string>0x00a2</string>
<key>spdisplays_rom-revision</key>
<string>3707</string>
<key>spdisplays_vendor</key>
<string>NVIDIA (0x10de)</string>
<key>spdisplays_vram</key>
<string>1024 MB</string>
<key>sppci_bus</key>
<string>spdisplays_pcie_device</string>
<key>sppci_device_type</key>
<string>spdisplays_gpu</string>
<key>sppci_model</key>
<string>NVIDIA GeForce GTX 675MX</string>
</dict>
</array>
<key>_parentDataType</key>
<string>SPHardwareDataType</string>
<key>_properties</key>
<dict>
<key>_name</key>
<dict>
<key>_isColumn</key>
<string>YES</string>
<key>_order</key>
<string>0</string>
</dict>
<key>spdisplays_coreimage</key>
<dict>
<key>_order</key>
<string>164</string>
</dict>
<key>spdisplays_depth</key>
<dict>
<key>_order</key>
<string>150</string>
</dict>
<key>spdisplays_device-id</key>
<dict>
<key>_order</key>
<string>165</string>
</dict>
<key>spdisplays_display-product-id</key>
<dict>
<key>_order</key>
<string>159</string>
</dict>
<key>spdisplays_display-serial-number</key>
<dict>
<key>_order</key>
<string>161</string>
</dict>
<key>spdisplays_display-vendor-id</key>
<dict>
<key>_order</key>
<string>160</string>
</dict>
<key>spdisplays_display-week</key>
<dict>
<key>_order</key>
<string>162</string>
</dict>
<key>spdisplays_display-year</key>
<dict>
<key>_order</key>
<string>163</string>
</dict>
<key>spdisplays_display_type</key>
<dict>
<key>_order</key>
<string>130</string>
</dict>
<key>spdisplays_displayport_device</key>
<dict>
<key>_order</key>
<string>171</string>
</dict>
<key>spdisplays_gmux-version</key>
<dict>
<key>_order</key>
<string>176</string>
</dict>
<key>spdisplays_main</key>
<dict>
<key>_order</key>
<string>165</string>
</dict>
<key>spdisplays_mirror</key>
<dict>
<key>_order</key>
<string>166</string>
</dict>
<key>spdisplays_mirror_status</key>
<dict>
<key>_order</key>
<string>167</string>
</dict>
<key>spdisplays_online</key>
<dict>
<key>_order</key>
<string>168</string>
</dict>
<key>spdisplays_pcie_width</key>
<dict>
<key>_order</key>
<string>40</string>
</dict>
<key>spdisplays_quartzextreme</key>
<dict>
<key>_order</key>
<string>169</string>
</dict>
<key>spdisplays_resolution</key>
<dict>
<key>_order</key>
<string>145</string>
</dict>
<key>spdisplays_retina</key>
<dict>
<key>_order</key>
<string>146</string>
</dict>
<key>spdisplays_revision-id</key>
<dict>
<key>_order</key>
<string>170</string>
</dict>
<key>spdisplays_rom-revision</key>
<dict>
<key>_order</key>
<string>175</string>
</dict>
<key>spdisplays_rotation</key>
<dict>
<key>_order</key>
<string>170</string>
</dict>
<key>spdisplays_vendor</key>
<dict>
<key>_order</key>
<string>155</string>
</dict>
<key>spdisplays_vram</key>
<dict>
<key>_order</key>
<string>135</string>
</dict>
<key>sppci_bus</key>
<dict>
<key>_isColumn</key>
<string>YES</string>
<key>_order</key>
<string>25</string>
</dict>
<key>sppci_device-id</key>
<dict>
<key>_order</key>
<string>50</string>
</dict>
<key>sppci_device_type</key>
<dict>
<key>_isColumn</key>
<string>YES</string>
<key>_order</key>
<string>20</string>
</dict>
<key>sppci_indentifer</key>
<dict>
<key>_order</key>
<string>180</string>
</dict>
<key>sppci_kextinfo</key>
<dict>
<key>_order</key>
<string>185</string>
</dict>
<key>sppci_model</key>
<dict>
<key>_order</key>
<string>1</string>
</dict>
<key>sppci_name</key>
<dict>
<key>_order</key>
<string>10</string>
</dict>
<key>sppci_revision-id</key>
<dict>
<key>_order</key>
<string>90</string>
</dict>
<key>sppci_rom-revision</key>
<dict>
<key>_order</key>
<string>80</string>
</dict>
<key>sppci_slot_name</key>
<dict>
<key>_isColumn</key>
<string>YES</string>
<key>_order</key>
<string>30</string>
</dict>
<key>sppci_subsystem-id</key>
<dict>
<key>_order</key>
<string>70</string>
</dict>
<key>sppci_subsystem-vendor-id</key>
<dict>
<key>_order</key>
<string>60</string>
</dict>
<key>sppci_vendor-id</key>
<dict>
<key>_order</key>
<string>35</string>
</dict>
<key>volumes</key>
<dict>
<key>_detailLevel</key>
<string>0</string>
</dict>
</dict>
<key>_timeStamp</key>
<date>2015-05-15T16:03:53Z</date>
<key>_versionInfo</key>
<dict>
<key>com.apple.SystemProfiler.SPDisplaysReporter</key>
<string>275</string>
</dict>
</dict>
</array>
</plist>

sardesm
Contributor

Got it, thank you for your help.

mm2270
Legendary Contributor III

In case anyone comes to this thread, here's a different version of an EA that will pull connected displays and their respective resolution. As mentioned above, only works with 10.9 and 10.10 right now. Not sure if there's really a way to make it work effectively with older OSes, but I'll leave that to someone else to try if they're so inclined.

#!/bin/bash

screens=$(system_profiler SPDisplaysDataType -xml | grep -A2 "</data>" | awk -F'>|<' '/_name/{getline; print $3}')
res=$(system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/_spdisplays_pixels/{getline; print $3}')

while read item; do
    screensArr+=("$item")
done < <(echo "$screens")

while read scsize; do
    resArr+=("$scsize")
done < <(echo "$res")

x=0
for item in "${screensArr[@]}"; do
    displayResults+=("Kind: ${item},   Resolution: ${resArr[$x]}")
    let x=$((x+1))
done

echo "<result>$(printf '%s
' "${displayResults[@]}")</result>"

Example output with 2 external displays connected to a MacBook Pro running 10.9.5:

Kind: Color LCD,    Resolution: 2560 x 1600
Kind: Thunderbolt Display,  Resolution: 2560 x 1440
Kind: LT1952p Wide, Resolution: 1440 x 900

If there isn't already something like this up there, I may add this to the Extension Attribute section here.

jchin-ria
New Contributor

Does anyone have an updated Extension Attribute script for this that works in macOS 12 ?

dwenger
Release Candidate Programs Tester

I've had reasonably good results with this variation:

#!/bin/zsh

screens=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/_name/{getline; print $3}' | sed '/^$/d')
pixels=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/_spdisplays_pixels/{getline; print $3}')
res=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/_spdisplays_resolution/{getline; print $3}')

while read item; do
screensArr+=("${item}")
done < <(echo "${screens}")

while read scsize; do
resArr+=("${scsize}")
done < <(echo "${res}")

while read scpixels; do
pixelArr+=("${scpixels}")
done < <(echo "${pixels}")

pixinc=0
resinc=0
for item in "${screensArr[@]}"; do
displayResults+=("${item} -- Pixels: ${pixelArr[$pixinc]} -- Effective Resolution: ${resArr[$resinc]}")
let resinc=$((resinc+1))
let pixinc=$((pixinc+1))
done

echo "<result>$(printf '%s\n' "${displayResults[@]}")</result>"

 

Thanks.  I will test it in my environment.

jchin-ria
New Contributor

Here is my modified version that was tested and works on macOS 10+ (including 13 Ventura and 14 Sonoma).

#!/bin/bash

##########
#
# FUNCTION: return a list of connect Displays and their resolutions
#
# AUTHOR: Johnny Chin
#
##########

screens=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | grep -B2 "<key>_spdisplays_display-product-id</key>" | awk -F'>|<' '/_name/{getline; print $3}')
totalres=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/_spdisplays_pixels/{getline; print $3}')
displayres=$(/usr/sbin/system_profiler SPDisplaysDataType -xml | awk -F'>|<' '/spdisplays_resolution/{getline; print $3}')

while read item; do
    screensArr+=("$item")
done < <(echo "$screens")

while read scsize; do
    totalresArr+=("$scsize")
done < <(echo "$totalres")

while read scres; do
    displayresArr+=("$scres")
done < <(echo "$displayres")

x=0
for item in "${screensArr[@]}"; do
    displayResults+=("Display: ${item},  Resolution: ${totalresArr[$x]},  Current: ${displayresArr[$x]}")
    let x=$((x+1))
done

echo "<result>"; echo "$(printf '%s
' "${displayResults[@]}")"; echo "</result>"

exit 0

and the Extension Attribute looks like this:

Display: Color LCD, Resolution: 3456 x 2234, Current: 1728 x 1117 @ 120.00Hz
Display: DELL UP2720Q, Resolution: 5120 x 2880, Current: 2560 x 1440 @ 60.00Hz

Thank you for all those who provide code and inspired this one.