feat(macos): add low power mode management functions (#13517)

This commit is contained in:
Enrico Maria Crisostomo authored and GitHub committed 2026-12-04 11:59:24 +01:00
1 parent 6d5348a397
commit 5b2db7b495
3 files changed
+74 -22

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
function lpm() {
local sw_vers=$(sw_vers -productVersion 2>/dev/null)
autoload is-at-least
if [[ -z "$sw_vers" ]] || ! is-at-least 12.0 $sw_vers; then
echo "Error: Low Power Mode requires macOS 12.0 (Monterey) or later" >&2
echo "Current version: ${sw_vers:-unknown}" >&2
return 1
fi
local lpm_status
case "${1:-toggle}" in
on)
sudo pmset -a lowpowermode 1
;;
off)
sudo pmset -a lowpowermode 0
;;
status)
lpm_status=$(pmset -g | awk '/lowpowermode/ {print $2}')
if [[ "$lpm_status" == "1" ]]; then
echo "enabled"
elif [[ "$lpm_status" == "0" ]]; then
echo "disabled"
else
echo "unknown" >&2
return 3
fi
;;
toggle)
lpm_status=$(pmset -g | awk '/lowpowermode/ {print $2}')
if [[ "$lpm_status" == "1" ]]; then
sudo pmset -a lowpowermode 0
elif [[ "$lpm_status" == "0" ]]; then
sudo pmset -a lowpowermode 1
else
echo "Unable to determine current status to toggle" >&2
return 3
fi
;;
*)
echo "usage: lpm [on|off|status|toggle]" >&2
return 2
;;
esac
}