This repository was archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatteryHealth.zsh
More file actions
36 lines (30 loc) · 1.32 KB
/
BatteryHealth.zsh
File metadata and controls
36 lines (30 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/zsh
# Source: https://github.com/kandji-inc/support/blob/main/Scripts/audit-scripts/alert_batteryhealth.zsh
# Script is designed to trigger an alert in Kandji if the battery condition is not normal and/or if the cycle count has reached a given threshold.
# Inspired by Matt Wilson's original batteryhealth script.
#Amount of cycles after you which you'd want to receive an alert.
cycleAlert=1000
##############################################################
# VARIABLES
##############################################################
#Determine model
model=$(system_profiler SPHardwareDataType | grep "Model Name:" | cut -d ' ' -f 9)
##############################################################
# MAIN
##############################################################
if [[ "$model" =~ "Book" ]]; then
#Determine battery condition
batteryCondition=$(system_profiler SPPowerDataType | grep "Condition" | xargs)
batteryCycles=$(system_profiler SPPowerDataType | grep "Cycle Count" | awk '{print $3}')
if [[ $batteryCondition == "Condition: Normal" && $batteryCycles -lt $cycleAlert ]]; then
echo "$batteryCondition, Battery cycle count is $batteryCycles"
exit 0
else
echo "WARNING! $batteryCondition, Battery cycle count is $batteryCycles."
exit 1
fi
else
echo "This computer is not a MacBook"
exit 0
fi
exit 0