Skip to content
Joey Wang
Menu

Search

Full Stack Development

Auditing USB-C Cable Quality from macOS Terminal

A macOS Terminal script that reads the I/O Kit registry to check negotiated wattage and voltage, so you can tell a fast USB-C cable from a slow one.

· 2 min read

notesengineering #macos#usb-c#terminal#scripting

Audio summary

Plug a MacBook into a premium-looking braided cable and the battery percentage barely moves. In the world of USB-C, looks are deceiving: a cable can be physically beefy but electronically limited to 60W, or fail to negotiate Power Delivery (PD) at all.

Instead of buying a USB-C voltmeter, you can read the macOS I/O Kit registry to see exactly what’s happening inside the copper.

The Science of the “Handshake”

USB-C isn’t just a “dumb” wire. High-performance cables contain an E-Marker chip in the connector. This chip “talks” to your Mac’s system controller to tell it how much current it can safely carry. Without this chip, your Mac defaults to a “Safety First” mode, capping power to avoid overheating the cable.


The “Cable Auditor” Script

To make this data accessible, we can wrap several complex macOS commands into a single Bash script. This script queries the system for negotiated wattage, real-time voltage, and current flow.

How to Create the Tool:

  1. Open Terminal.
  2. Type nano cable_audit.sh.
  3. Paste the code below.
  4. Press Ctrl+O, Enter, then Ctrl+X.
  5. Run chmod +x cable_audit.sh to give it permission to run.

The Code:

#!/bin/bash

# --- USB-C CABLE & POWER AUDIT SCRIPT ---
# Designed for macOS to detect cable quality

echo "---------------------------------"
echo "   MACBOOK POWER CABLE AUDIT     "
echo "---------------------------------"

# 1. Negotiated Wattage
WATTAGE=$(system_profiler SPPowerDataType | grep "Wattage (W)" | awk '{print $3}')

# 2. Electrical Details (Voltage/Current)
# We pull from AppleRawAdapterDetails
RAW_DATA=$(ioreg -rw0 -l | grep -i "AppleRawAdapterDetails")
VOLTS_MV=$(echo "$RAW_DATA" | grep -o '"Voltage"=[0-9]*' | cut -d= -f2)
AMPS_MA=$(echo "$RAW_DATA" | grep -o '"Current"=[0-9]*' | cut -d= -f2)

# 3. Output Results
if [ -z "$WATTAGE" ]; then
    echo "STATUS: No Power Adapter Detected."
    exit
fi

echo "Negotiated Capacity: ${WATTAGE}W"

if [ ! -z "$VOLTS_MV" ]; then
    # Calculate Volts and Amps for readability
    VOLTS_V=$(echo "scale=2; $VOLTS_MV / 1000" | bc)
    AMPS_A=$(echo "scale=2; $AMPS_MA / 1000" | bc)
    echo "Actual Flow: ${VOLTS_V}V @ ${AMPS_A}A"
fi

echo "---------------------------------"

# 4. Grading Logic
if [ "$WATTAGE" -gt 60 ]; then
    echo "GRADE: [PRO] Supports 100W+ (E-Marker Chip detected)"
elif [ "$WATTAGE" -eq 60 ]; then
    echo "GRADE: [STANDARD] 60W Limit (No E-Marker or 3A capped)"
else
    echo "GRADE: [LOW] Slow charging or legacy cable"
fi

How to Read the Results

1. The Wattage Gap

If you have a 96W or 140W Apple Power Brick but the script reports 60W, your cable is the bottleneck. It lacks the internal wiring to handle high amperage.

2. The Voltage Stability

A high-quality Power Delivery (PD) cable should lock onto 20V (reported as 20.00V in the script). If you see the voltage dropping to 5V or 9V under load, the cable has too much internal resistance and is dropping the connection.

3. Physical Health Check

Run the script, then gently wiggle the cable near the connectors. Run it again. If the Current (A) value fluctuates wildly or the Negotiated Capacity disappears, the internal solder points are failing.


Data doesn’t lie. This script sorts your fast cables from your trash ones in seconds. Next time the Mac feels like it’s charging slowly, don’t guess, check the terminal.