Skip to main content
Jamf Nation, hosted by Jamf, is a dynamic and knowledgeable community of Apple-focused IT admins and Jamf Pro users. Join us in person, in October, for the annual Jamf Nation User Conference (JNUC) to discover new and better ways to manage Apple devices.
CCA Badge

EA for USB-C?

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

Like Comment
SOLVED Posted: 9/6/17 at 2:18 PM by pete_c

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.

Like
CCA Badge CCE Badge CMA Badge CUG Badge
SOLVED Posted: 9/6/17 at 2:39 PM by donmontalvo

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
Like
CCA Badge CMA Badge CUG Badge
SOLVED Posted: 9/6/17 at 4:03 PM by stevewood

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

Like
CCA Badge CCE Badge
SOLVED Posted: 9/6/17 at 5:20 PM by Look

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.

Like
CCA Badge CCE Badge CMA Badge CUG Badge
SOLVED Posted: 9/6/17 at 6:36 PM by donmontalvo

+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
Like
CCA Badge
SOLVED Posted: 9/13/17 at 11:55 AM by Sonic84

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#
Like
CCA Badge
SOLVED Posted: 9/13/17 at 12:35 PM by emily

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.

Like