Posted on 09-06-2017 11:49 AM
Hello, does anyone have an EA for identifying whether or not a inventoried Mac has a USB-C port?
Solved! Go to Solution.
Posted on 09-06-2017 12:39 PM
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
Posted on 09-06-2017 12:18 PM
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.
Posted on 09-06-2017 12:39 PM
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
Posted on 09-06-2017 02:03 PM
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:
Posted on 09-06-2017 03:20 PM
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.
Posted on 09-06-2017 04:36 PM
+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
Posted on 09-13-2017 09:55 AM
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#
Posted on 09-13-2017 10:35 AM
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
.