From 49f5daaa459bfd2a60821f77c66a105ac005e575 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 4 Oct 2025 01:05:47 +0200 Subject: [PATCH] Use js4jiang5's implementation of smc_read_hex() to fix smc output parsing error --- battery.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/battery.sh b/battery.sh index c6c0613..8fa9036 100755 --- a/battery.sh +++ b/battery.sh @@ -194,10 +194,13 @@ function detect_smc_capabilities() { } function smc_read_hex() { - local key=$1 - local value=$(sudo -n smc -k "$key" -r 2>/dev/null | awk '{print $4}') - value=${value//:/} - echo "$value" + key=$1 + line=$(echo $(smc -k $key -r)) + if [[ $line =~ "no data" ]]; then + echo + else + echo ${line#*bytes} | tr -d ' ' | tr -d ')' + fi } function smc_write_hex() {