OS X: Current CPU temperature on command line

related: os x , mac , one-liner , smc

Apple doesn’t provide any easy way to query the temperature and fan speed on an Intel Mac running OS X 10.5+.

You can access the SMC information with the IOKit API, by asking the kernel for a list of registered ‘AppleSMC’ devices.  It’s a pain in the ass, but a nice fellow has made a GPL’d program that handles it for you:

Fan Control (smc utility)

It also comes in the bundle with smcFanControl.

It returns raw sensor readings, so here’s a huge one-liner to get the current CPU temperature:

smc -k TC0D -r | sed ’s/.\*bytes \(.\*\))/\1/’ |sed ’s/\([0-9a-fA-F]\*\)/0x\1/g’ | perl -ne 'chomp; ($low,$high) = split(/ /); print (((hex($low)\*256)+hex($high))/4/64); print “C\n”;’