Friday, November 28, 2014

#1 2005-08-03 03:31:25 pm

Subway
Member
Registered: 2005-08-03
Posts: 13

Is there a way to get the CPU(s) temperature?

Is there a way to get the CPU(s) temperature?

Maybe with some additional Objective-C includes if there's no clean AS way?

Fredi

Last edited by Subway (2005-08-03 03:31:53 pm)

Offline

 

#2 2005-08-03 03:35:41 pm

Vincent
Member
From: Germany
Registered: 2004-04-06
Posts: 205

Re: Is there a way to get the CPU(s) temperature?

The widget "miniCpuHeat" seems to use a Javascript way to get the heat!
Maybe you can find out where it gets the info from roll

Offline

 

#3 2005-08-03 03:42:00 pm

Subway
Member
Registered: 2005-08-03
Posts: 13

Re: Is there a way to get the CPU(s) temperature?

Thx. Will have a look ...

Fredi

Offline

 

#4 2005-08-03 09:13:45 pm

themacgeek
Member
From: Cherry Hill, NJ
Registered: 2005-04-08
Posts: 130
Website

Re: Is there a way to get the CPU(s) temperature?

it is actually a perl script that detects the temp (sensors.pl)


"I love it when a plan comes together."
           ~John "Hannible" Smith from The A-Team

Offline

 

#5 2005-08-03 09:18:21 pm

themacgeek
Member
From: Cherry Hill, NJ
Registered: 2005-04-08
Posts: 130
Website

Re: Is there a way to get the CPU(s) temperature?

well to be a bit more helpful, copy that file to your home directory and in terminal type "perl sensors.pl" and hit return

in AS

Applescript:

do shell script "perl sensors.pl"


"I love it when a plan comes together."
           ~John "Hannible" Smith from The A-Team

Offline

 

#6 2005-08-04 02:16:35 am

jonn8
Member
From: New York
Registered: 2003-05-01
Posts: 1766
Website

Re: Is there a way to get the CPU(s) temperature?

I'm sure there are better ways of doing this but try:

Applescript:

property return_f : false

try
   set the_result to (do shell script "ioreg -c IOHWSensor | grep -vE '\\{|\\}|\\+\\-o'")'s paragraphs
on error
   return "unknown"
end try
set the_temps to {}
repeat with i from 1 to (count the_result)
   try
       set this_value to item i of the_result
       set this_type to item (i + 2) of the_result
       set this_key to item (i + 3) of the_result
       if (this_value contains "current-value") and (this_type contains "CPU") and (this_key contains "temperature") then
           set end of the_temps to this_value's word -1 as integer
       end if
   on error
       exit repeat
   end try
end repeat
set the_sum to 0
repeat with i in the_temps
   set the_sum to the_sum + ((i's contents) / (2 ^ 16))
end repeat
set this_temp to the_sum / (count the_temps)
if return_f then
   return ((this_temp * (9 / 5) + 32) as Unicode text) & "°F"
else
   return (this_temp as Unicode text) & "°C"
end if

Jon

Last edited by jonn8 (2005-08-04 02:17:39 am)

Offline

 

#7 2005-08-04 03:32:57 am

Subway
Member
Registered: 2005-08-03
Posts: 13

Re: Is there a way to get the CPU(s) temperature?

Thx a lot everyone. smile

Fredi

Offline

 

#8 2005-08-05 07:15:21 am

Subway
Member
Registered: 2005-08-03
Posts: 13

Re: Is there a way to get the CPU(s) temperature?

jonn8 wrote:

I'm sure there are better ways of doing this but try:

...

Jon

I just moved to my dual G5 and your script gave me a "division by 0" error. I cahnged the code a bit to solve that problem, but it looks like it can't get the temperature of my G5. Guess the problem has something to do with having multiple CPU's. Any ideas how I could solve this?

Fredi

Offline

 

#9 2006-12-25 02:12:00 am

WoodenBrain
Member
Registered: 2004-11-12
Posts: 190
Website

Re: Is there a way to get the CPU(s) temperature?

Yes, I tried this on my MacBook Pro, and initially got the division by zero error.  Logically, this is because the results of the shell script does not contain "CPU" and "temperature", so the list the_temps is empty and so count the_temps = 0.

Here is the_result:

{"    | |   |     | |       \"polling-period\" = 18446744073709551615", "    | |   |     | |       \"current-value\" = 6553600", "    | |   |     | |       \"location\" = \"GPU\"", "    | |   |     | |       \"type\" = \"gpu\"", "    | |   |     | |       \"CFBundleIdentifier\" = \"com.apple.driver.AppleHWSensor\"", "    | |   |     | |       \"IOClass\" = \"IOHWSensor\"", "    | |   |     | |       \"version\" = 2", "    | |   |     | |       \"zone\" = <00000002>", "    | |   |     | |       \"IOProbeScore\" = 0", "    | |   |     | |       \"IOMatchCategory\" = \"IODefaultMatchCategory\"", "    | |   |     | |       \"polling-period-ns\" = 18446744073709551615", "    | |   |     | |       \"IOProviderClass\" = \"IOService\"", "    | |   |     | |       \"sensor-id\" = 6", "    | |   |     | |     "}


Wooden Brain Concepts
http://www.woodenbrain.com

Offline

 

#10 2007-01-28 09:50:14 pm

doug pennington
Member
Registered: 2006-06-26
Posts: 1

Re: Is there a way to get the CPU(s) temperature?

This works on ibook. Just turn it into an Applescript. When you get the values then divide by 65536 and that gives C temp. Then take that # times 9/5+32 and you'll have F temp.



#!/bin/bash
ioreg -l | grep "current-value"
ioreg -l | grep "hwsensor-location"

Offline

 

#11 2009-09-26 02:33:43 pm

jjones
Member
Registered: 2003-01-22
Posts: 8

Re: Is there a way to get the CPU(s) temperature?

This may break on other macs, and I'm sure it could be a little more elegant, but works so far on my dual G5.

Applescript:


set the_result to (do shell script "ioreg -c IOHWSensor | grep -vE '\\{|\\}|\\+\\-o'")'s paragraphs

set all_display to ""
repeat with i from 0 to 16
   
   set jump to 14
   set the_location to item (3 + (jump * i)) of the_result
   set the_location to characters 41 thru ((count of characters of the_location) - 1) of the_location as string
   set the_type to item (4 + (jump * i)) of the_result
   set the_text to item (2 + (jump * i)) of the_result as string
   set the_text to characters 44 thru (count of characters of the_text) of the_text as string --(length of item 2 of the_result)
   set the_type to characters 37 thru ((count of characters of the_type) - 1) of the_type as string
   if the_type = "temperature" then
       set all_display to all_display & "
"
& the_location & ": " & ((the_text / 65536) * (9 / 5)) + 32 & " F" as string
   end if
end repeat

display dialog all_display

results...

DRIVE BAY: 89.6 F
BACKSIDE: 129.2 F
U3 HEATSINK: 168.125 F
CPU A AD7417 AMB: 139.55 F
CPU B AD7417 AMB: 130.1 F


-Jeff Jones


Filed under: temp

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.027 seconds, 9 queries executed ]

RSS (new topics) RSS (active topics)