MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
April
Sun Mon Tue Wed Thu Fri Sat
     
21
   
2015
Months
Apr


Tue, Apr 21, 2015 11:25 pm

Checking the battery temperature for a MacBook Pro laptop

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

[/os/os-x] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo