EA for USB-C?

Sonic84
Contributor III

Hello, does anyone have an EA for identifying whether or not a inventoried Mac has a USB-C port?

1 ACCEPTED SOLUTION

donmontalvo
Esteemed Contributor III

Works with double brackets in theif statement:

#!/bin/sh

# first attempt at USB-C via USB 3.1 sys_prof EA

usb=$(/usr/sbin/system_profiler SPUSBDataType | grep 3.1)

if [[ -z $usb ]];
then
        echo "<result>False</result>"
else
        echo "<result>True</result>"
fi
--
https://donmontalvo.com

View solution in original post

7 REPLIES 7

pete_c
Contributor III

Off the top of my head..

#!/bin/sh

# first attempt at USB-C via USB 3.1 sys_prof EA

usb=$(/usr/sbin/system_profiler SPUSBDataType | grep 3.1)

if [ -z $usb ];
then
        echo "<result>False</result>"
else
        echo "<result>True</result>"
fi

Someone less brain-dead than I currently am can probably suggest a better means than using the -z in that if statement.. Also I only have means to test that against 2016-2017 MBPs, nothing like a Mac Pro with a PCI expansion.

donmontalvo
Esteemed Contributor III

Works with double brackets in theif statement:

#!/bin/sh

# first attempt at USB-C via USB 3.1 sys_prof EA

usb=$(/usr/sbin/system_profiler SPUSBDataType | grep 3.1)

if [[ -z $usb ]];
then
        echo "<result>False</result>"
else
        echo "<result>True</result>"
fi
--
https://donmontalvo.com

stevewood
Honored Contributor II
Honored Contributor II

If you're going to be polling system_profiler for the information, might I suggest doing it via a weekly or monthly policy instead of via the EA itself? Create a policy that grabs the USB info and writes it to a file, a plist is what I use, and then read the plist in the EA. This will speed up your recon since system_profiler can be notoriously slow to grab data from. I have a write up on how to use plist files for grabbing data on my blog:

Collecting Data Using PLIST Files

Look
Valued Contributor III

Personally I find system_profiler is fine as long as you specify the SPDataType you require.
If you leave it open ended and then try to extract the data it's a total pig.
But that above query with SPUSBDataType specified is only taken some small fraction of a second on an SSD based machine.

donmontalvo
Esteemed Contributor III

+1 to @stevewood and @Look...we move anything that takes longer than 0.1 seconds to a policy that runs a script that outputs to a file that an EA scoops up.

This one takes barely over that long, so we leave it in an EA.

$ time /private/tmp/test.sh 
<result>True</result>

real    0m0.108s
user    0m0.035s
sys     0m0.026s
--
https://donmontalvo.com

Sonic84
Contributor III

Thank you for all the responses! you got me pointed in the right direction.

I used ioreg in stead and keyed off of "TypeCPort" description in Apple's USB host. Granted, this method will fail if Apple ever changes the name of the hardware host adapter "AppleUSB30XHCITypeCPort".

Thank you!

#!/bin/bash
typec="$(ioreg -bl -p IOUSB | grep TypeCPort)"
if [[ -z ${typec} ]]; then
        echo "<result>False</result>"
else
        echo "<result>True</result>"
fi

speed comparison for completeness:

bash-3.2# time /Users/me/Desktop/ioreg.sh 
<result>True</result>

real    0m0.023s
user    0m0.009s
sys 0m0.013s
bash-3.2# time /Users/me/Desktop/profiler.sh 
<result>True</result>

real    0m0.207s
user    0m0.063s
sys 0m0.060s
bash-3.2#

emily
Valued Contributor III
Valued Contributor III

If you're looking to differentiate Touchbar Macs out of the USB-C detecting, I'd recommend checking this out:
https://www.rderewianko.com/detecting-a-touchbar-mac/

The last EA in the post looks for AppleEmbeddedOSSupportHost.