Hi guys
Im trying to work out a script and wondered if anyone may be able to help?
I am running a script at logout that will detect if the AC power is still plugged in and remind people to unplug it before they leave the office to avoid damage to battery cells.
The problem i have is trying to work out to get an if argument that will detect if the battery power is more than 80%.
This is what i have so far
#!/bin/bash
##### ENVIRONMENT VARIABLES #####
# Specify a laptop using system profiler
Laptop=`system_profiler SPHardwareDataType | grep -E "MacBook"`
# Get the battery percentage
Bat=`ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c[""MaxCapacity""]; print (max>0? 100*c[""CurrentCapacity""]/max: "?")}'`
# Specifying the message
MSG="Your power cable is still plugged in.
Remove it please otherwise you are at risk of damaging the cells in the battery leaving it plugged in for long periods of time.
Thank you"
#### DO NOT MODIFY BELOW THIS LINE ####
## Check if all the conditions are met
if [ "$Laptop" ] && [[ $(pmset -g ps | head -1) =~ "AC Power" ]] ; then
# Display the message with a 5 minute timeout
sudo /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
-windowType utility -title "Warning" -description "$MSG" -timeout 300 -button1 "OK"
-icon /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns -iconSize 96
fi
exit 0