Skip to content

Instantly share code, notes, and snippets.

@alazycoder101
Created February 3, 2026 18:06
Show Gist options
  • Select an option

  • Save alazycoder101/30eb29dd1a1be01f94094845bc39f1e4 to your computer and use it in GitHub Desktop.

Select an option

Save alazycoder101/30eb29dd1a1be01f94094845bc39f1e4 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "--- USB-C CABLE & POWER AUDIT ---"
echo "Date: $(date)"
echo "---------------------------------"
# 1. Get Negotiated Wattage
WATTAGE=$(system_profiler SPPowerDataType | grep "Wattage (W)" | awk '{print $3}')
printf "Negotiated Wattage: %sW\n" "$WATTAGE"
# 2. Get Voltage and Current from IOReg
# Note: Values are in mV and mA, so we divide by 1000 for standard units
VOLTS_MV=$(ioreg -rw0 -l | grep "Voltage" | awk '{print $4}')
AMPS_MA=$(ioreg -rw0 -l | grep "Current" | awk '{print $4}')
if [ -z "$VOLTS_MV" ]; then
echo "Voltage: No data (Is the charger connected?)"
else
VOLTS_V=$(echo "scale=2; $VOLTS_MV / 1000" | bc)
AMPS_A=$(echo "scale=2; $AMPS_MA / 1000" | bc)
echo "Real-time Voltage: ${VOLTS_V}V"
echo "Real-time Current: ${AMPS_A}A"
fi
# 3. Get Charging Status
STATE=$(pmset -g batt | grep "AC Power" | wc -l)
if [ $STATE -eq 1 ]; then
echo "Charging State: OK (Drawing from AC)"
else
echo "Charging State: WARNING (Not drawing enough AC power)"
fi
echo "---------------------------------"
# Simple Logic for Cable Grading
if [ "$WATTAGE" -gt 60 ]; then
echo "GRADE: PRO CABLE (E-Marker detected, 5A support)"
elif [ "$WATTAGE" -eq 60 ]; then
echo "GRADE: STANDARD CABLE (3A support, no E-Marker)"
else
echo "GRADE: LOW POWER / WEAK CABLE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment