Skip to content

Instantly share code, notes, and snippets.

@oboje
Created April 28, 2020 11:59
Show Gist options
  • Save oboje/7786d442786101b78c618a37b0ef11fd to your computer and use it in GitHub Desktop.
Save oboje/7786d442786101b78c618a37b0ef11fd to your computer and use it in GitHub Desktop.
mac os input voltage stat
#!/bin/bash
b=$(system_profiler SPPowerDataType)
amp=$(echo "$b" | grep 'Amperage (mA):' | cut -d ':' -f 2 | xargs)
volt=$(echo "$b" | grep 'Voltage (mV):' | cut -d ':' -f 2 | xargs)
power=$(($amp * $volt / 1000))
echo "$b" | grep --color=never -A 1 'Battery Information:'
echo "$b" | grep --color=never -A 1 'Amperage (mA)'
echo " Total Power (mW): $power"
echo ""
echo "$b" | grep --color=never -A 99 'AC Charger Information:'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment