I wanted to check the temperature of components in a MacBook Pro laptop running OS X 10.8.5, aka Mountain Lion, from the command line. A Bash script by jondthompson, which is a fork of a script posted by earlonrails, to check the battery temperature that can be run from a Terminal window can be found at GitHub Gist at battery_temperature.sh. I've also included the code below.
#!/bin/bash
# battery_temperature for mac osx 10.9.2
if [ `uname` == "Darwin" ]; then
if [ "$1" == "-h" ]; then
echo "Usage: $(basename $0 ".sh") [option]"
echo " -l also show Model Name and Processor Name"
echo " -h display this help message"
exit
fi
# -l display Model Name and Processor Name
if [ "$1" == "-l" ]; then
system_profiler SPHardwareDataType | awk '/Model Name/ || /Processor Name/' | sed 's/[^:]*: //' | awk '{ printf $0 " " }'
echo
fi
# sensor data
temperature=`ioreg -r -n AppleSmartBattery | grep Temperature | cut -c23-`
temperature_celsius=`echo "scale = 2; $temperature / 100.0" | bc`
echo "AppleSmartBattery Temperature: "
echo $temperature_celsius °C
temperature_fahrenheit=`echo "scale = 2; ($temperature_celsius * (9 / 5)) + 32.0" | bc`
echo $temperature_fahrenheit °F
# error message if unsupported machine
else
echo -e "\nThis appears not to be an OS X machine\n"
fi
After making the script executable, when I ran it on a 15-inch, Mid 2009 MacBook Pro laptop, I saw the following:
$ chmod +x battery_temperature.sh $ ./battery_temperature.sh AppleSmartBattery Temperature: 30.46 °C 86.82 °F