Read AppleSmartBattery Temperature value

#!/bin/bash

# Read AppleSmartBattery Temperature value
batteryTemperature=`ioreg -r -n AppleSmartBattery | grep Temperature | cut -c23-`

# Convert to Celsius
temperatureCelsius=`echo $batteryTemperature / 100 | bc`

# Convert to Fahrenheit
temperatureFahrenheit=`echo "($temperatureCelsius * (9 / 5)) + 32" | bc`

echo "Battery Temperature:"
echo $temperatureCelsius °C
echo $temperatureFahrenheit °F

# Check if is external connected
externalConnected=`ioreg -l | grep ExternalConnected | cut -d'=' -f 2`
echo External Connected: $externalConnected

 

Top