Skip to contentSkip to conversation

Fix power checking on OS X

PATCH In review Panagiotis Astithas 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix power checking on OS X

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

---
 contrib/hooks/pre-auto-gc-battery | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/hooks/pre-auto-gc-battery +1 -1
index 9d0c2d1..6a2cdeb 100755
@@ -33,7 +33,7 @@ elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
 then
 	exit 0
 elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
-	grep -q "Currently drawing from 'AC Power'"
+	grep -q "drawing from 'AC Power'"
 then
 	exit 0
 fi
Signature · 1 line
2.4.1
#1 lore raw
Quoted 4 lines · Panagiotis Astithas

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

Would it make sense to try to future-proof this further by searching only for "'AC" (including the leading single-quote) or just "AC" (without the leading quote)?

(Genuine question. I don't have a strong feeling about it.)

Quoted 17 lines

---

contrib/hooks/pre-auto-gc-battery +1 -2
index 9d0c2d1..6a2cdeb 100755
@@ -33,7 +33,7 @@ elif grep -q "AC Power \+: 1" /proc/pmu/info 2>/dev/null
 then
        exit 0
 elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
-       grep -q "Currently drawing from 'AC Power'"
+       grep -q "drawing from 'AC Power'"
 then
        exit 0
 fi
--

2.4.1

#2 lore raw
Quoted 11 lines · Eric Sunshine
Quoted 4 lines · Panagiotis Astithas

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

Would it make sense to try to future-proof this further by searching only for "'AC" (including the leading single-quote) or just "AC" (without the leading quote)?

(Genuine question. I don't have a strong feeling about it.)

It's a reasonable idea, although I'm wondering what are the odds of pmset changing to output a string when running on battery in the future, containing something like "no longer on 'AC Power'". That's probably too far out though.

#3 lore raw
Quoted 11 lines · Panagiotis Astithas
Quoted 10 lines · Eric Sunshine
Quoted 4 lines · Panagiotis Astithas

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

Would it make sense to try to future-proof this further by searching only for "'AC" (including the leading single-quote) or just "AC" (without the leading quote)?

Quoted 6 lines
Quoted 1 line

(Genuine question. I don't have a strong feeling about it.)

It's a reasonable idea, although I'm wondering what are the odds of pmset changing to output a string when running on battery in the future, containing something like "no longer on 'AC Power'". That's probably too far out though.

That was my concern, as well, hence not feeling strongly about it.

#4 lore raw
In reply to Panagiotis Astithas
Quoted 11 lines · Panagiotis Astithas
Quoted 10 lines · Eric Sunshine
Quoted 4 lines · Panagiotis Astithas

The output of "pmset -g batt" changed at some point from "Currently drawing from 'AC Power'" to the slightly different "Now drawing from 'AC Power'". Starting the match from "drawing" makes the check work in both old and new versions of OS X.

Would it make sense to try to future-proof this further by searching only for "'AC" (including the leading single-quote) or just "AC" (without the leading quote)?

Quoted 6 lines
Quoted 1 line

(Genuine question. I don't have a strong feeling about it.)

It's a reasonable idea, although I'm wondering what are the odds of pmset changing to output a string when running on battery in the future, containing something like "no longer on 'AC Power'". That's probably too far out though.

Once they start drawing from USB-C, they may stop referring to AC altogether; unless you have a crystal ball, it is futile to spend too many brain cycles to try futureproofing.

Prediction is very difficult, especially if it's about the future.