Get notified when your battery needs to be changed

Is there a way Keyboard Maestro can help me when my battery needs to be replaced.

I am NOT looking for a macro about how much energy I have left. Or this kind of information. :grinning:

I am looking for a way for Keyboard Maestro to get the following info: "Condition: Replace now". Keyboard Maestro would use this info as condition.

Once the condition is met, a "Large text" would display with "Set an appointment at the nearest Apple Store!"

A little like Steve_Solari did here: Dummy Tip Learned the Hard Way: Always test your code!

I already looked at pmset but didn't find anything helpful in the doc. Or, I probably didn't search well enough.

Thank you!

How about this shell command:

system_profiler SPPowerDataType | grep "Condition"

For me it displays:

Condition: Service Recommended

Which obviously needs attention, but it may be something like what you're looking for.

If this would work, let me know and I could help you write the macro. We could make it look for literally "Condition: Replace now" if you like instead.

Thanks! Exactly what I was looking for!

I googled your one line and found this StackOverflow thread.

What does the awk part do add?

system_profiler SPPowerDataType | grep "Condition" | awk '{print $2}'

Sad news, I have to change my my battery :joy:

1 Like

Funny you should ask about that part. I've been studying that very thing myself this weekend while learning Geektool, then moving on to Übersicht. I believe (someone correct me if I'm wrong here) 'grep' finds the line you want and 'awk' finds the column. Kind of like an address in an Excel spreadsheet. So the code string you posted would give me the word "Service" without the "Condition: " part.

$1 = Condition:
$2 = Service
$3 = Recommended

To get the whole phrase of the condition without the label, I'd use:

awk '{print $2" "$3}'

and get

Service Recommended

Notice the quotes around the space, to give me a literal space in between the two columns' contents in the output string.

1 Like

That makes so much sense now!

system_profiler SPPowerDataType | grep "Condition" | awk '{print $2" "$3}'

gave me

Replace Now