From 9bce4090fa3ed702b60ad002ff55c0c6212e3f12 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Wed, 26 Nov 2025 22:49:01 +0000 Subject: [PATCH] Use iSMC instead of custom cpu-temp tool Fixes #10 --- system-info/system-info-macOS.sh | 67 ++------------------------------ 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/system-info/system-info-macOS.sh b/system-info/system-info-macOS.sh index 5f2d8fb..7412dce 100755 --- a/system-info/system-info-macOS.sh +++ b/system-info/system-info-macOS.sh @@ -8,68 +8,7 @@ if [ ! -d $cache_dir ]; then mkdir -p $cache_dir fi -if [ ! -f $cache_dir/cpu-temp ]; then - clang -x objective-c -Wall -O2 -g -c -o $cache_dir/cpu-temp.o - << EOF -#import -#import -#include - -#define IOHIDEventFieldBase(type) (type << 16) -#define kIOHIDEventTypeTemperature 15 - -typedef struct __IOHIDEvent *IOHIDEventRef; -typedef struct __IOHIDServiceClient *IOHIDServiceClientRef; -typedef double IOHIDFloat; - -IOHIDEventSystemClientRef -IOHIDEventSystemClientCreate(CFAllocatorRef allocator); -int IOHIDEventSystemClientSetMatching(IOHIDEventSystemClientRef client, - CFDictionaryRef match); -IOHIDEventRef IOHIDServiceClientCopyEvent(IOHIDServiceClientRef, int64_t, - int32_t, int64_t); -CFStringRef IOHIDServiceClientCopyProperty(IOHIDServiceClientRef service, - CFStringRef property); -IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef event, int32_t field); - -int main(int argc, char *argv[]) { - NSDictionary *thermalSensors = @{ - @"PrimaryUsagePage" : [NSNumber numberWithInt:0xFF00], - @"PrimaryUsage" : [NSNumber numberWithInt:5], - }; - IOHIDEventSystemClientRef system = - IOHIDEventSystemClientCreate(kCFAllocatorDefault); - IOHIDEventSystemClientSetMatching(system, - (__bridge CFDictionaryRef)thermalSensors); - NSArray *serviceClients = - (__bridge NSArray *)IOHIDEventSystemClientCopyServices(system); - - long count = [serviceClients count]; - for (NSUInteger i = 0; i < count; i++) { - IOHIDServiceClientRef serviceClient = - (IOHIDServiceClientRef)serviceClients[i]; - NSString *name = (NSString *)IOHIDServiceClientCopyProperty( - serviceClient, (__bridge CFStringRef) @"Product"); - if ([name isEqualToString:[NSString stringWithUTF8String:argv[1]]]) { - IOHIDEventRef event = IOHIDServiceClientCopyEvent( - serviceClient, kIOHIDEventTypeTemperature, 0, 0); - NSNumber *value; - double temp = 0.0; - if (event != 0) { - temp = IOHIDEventGetFloatValue( - event, IOHIDEventFieldBase(kIOHIDEventTypeTemperature)); - } - value = [NSNumber numberWithDouble:temp]; - printf("%.1lf°C\n", [value doubleValue]); - break; - } - } - - return 0; -} -EOF - clang -o $cache_dir/cpu-temp $cache_dir/cpu-temp.o -framework Foundation -framework IOKit - rm $cache_dir/cpu-temp.o -fi +[ -f $cache_dir/cpu-temp ] && rm $cache_dir/cpu-temp # Cleanup cache file when interrupted. trap '[ -f $cache_file ] && rm $cache_file; exit' INT @@ -81,7 +20,9 @@ ioreg -w0 -l | grep BatteryInstalled &> /dev/null && \ while true; do # Get the current CPU temperature. - cpu_temp="`$cache_dir/cpu-temp 'PMU tdie1'` " + cpu_temp=$( + ~/.local/bin/iSMC -o json temp | jq '."PMU tdie1".quantity' | xargs printf "%.1f°C " + ) cpu_load=$(sudo powermetrics --format text \ --sample-rate 1200 --sample-count 1 --samplers cpu_power |