Query Machine's Charger Type Magsafe 2 or Thunderbolt 3

NickC
New Contributor

Like everyone, we are in a transition from laptops that use Magsafe 2 to Thunderbolt3/USB-C. Is there an easy way to reliably query machines charger type in inventory? Ideally setting it as an Extension Attribute under Hardware.

6 REPLIES 6

dgreening
Valued Contributor II

You can definitely script the collection of this data with the caveat that it only shows up in System Profiler - Power when connected.

junjishimazaki
Valued Contributor

Why would you base on the power adapter? Wouldn't it make more sense to base it on year and model if you are going to upgrade user's computer?

NickC
New Contributor

I want this because I have several hundred desks on several floors that use one of two setups (USB-A/Magsafe vs USB-C). If someone is moving desks I need to check what their machine needs vs what the current occupant's machine needs.
I am wondering if just pulling USB30Bus vs USB31Bus from system_profiler is good enough. I never thought this possible, but I may have stumbled upon the single upside to the absolutist switch from 3.0 to 3.1... Besides Mac Minis, are there any Mac's that have both USB-C and USB-A? Does anything use USB 3.1 over USB-A?
As an aside, does anyone have example scripts of pulling from system_profiler using json/jq?

junjishimazaki
Valued Contributor

Ah Ok, thank you for clarifying. As degreening using the system_profiler command. Something like this: system_profiler SPPowerDataType | grep "Name" | awk '{print $3}'

NickC
New Contributor

That seems to return the name of the battery. As part of SPPowerDateType there is: AC Charger Information:

Connected: Yes ID: 0x0aa1 Wattage (W): 85 Family: 0x0085 Serial Number: 0x00e25313 Charging: No

But I'm not sure how to interpret what Family means. Also like degreening said it only appears when it is actually connected to a charger.

I think maybe checking Thunderbolt type is sort of a way to go. I don't think anything has TB3 and a MagSafe. But I'm not sure how to actually find that either. But I can find its speed which is sort of correct. I don't think anything does 40 Gb/s and also has 20 Gb/s ports.

system_profiler SPThunderboltDataType | grep -m 1 Speed: | cut -c 24-26

I'll keep looking for a cleaner way to do this. If anyone comes up with a better idea let me know.

tlarkin
Honored Contributor
>>> import subprocess
>>> import plistlib
>>> 
>>> cmd = ['system_profiler', 'SPPowerDataType', '-xml']
>>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> out, err = proc.communicate()
>>> data = plistlib.readPlistFromString(out)
>>> print data[0]['_items'][3]['sppower_ac_charger_name']
87W USB-C Power Adapter

There is a python example of parsing plist output data from system_profiler