Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Created December 23, 2022 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/b3d734830eea981b27fb11b25c3c0ba2 to your computer and use it in GitHub Desktop.
Save rtrouton/b3d734830eea981b27fb11b25c3c0ba2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set separate power management settings for desktops and laptops
# If it's a laptop, the power management settings for "Battery" are set to have the computer sleep in 15 minutes,
# disk will spin down in 10 minutes, the display will sleep in 5 minutes and the display itself will dim to
# half-brightness before sleeping. While plugged into the AC adapter, the power management settings for "Charger"
# are set to have the computer never sleep, the disk doesn't spin down, the display sleeps after 30 minutes and
# the display dims before sleeping.
#
# If it's not a laptop (i.e. a desktop), the power management settings are set to have the computer never sleep,
# the disk doesn't spin down, the display sleeps after 30 minutes and the display dims before sleeping.
#
# Detects if this Mac is a laptop or not by checking the model ID for the word "Book" in the name.
IS_LAPTOP=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "Book")
if [[ -n "$IS_LAPTOP" ]]; then
/usr/bin/pmset -b sleep 15 disksleep 10 displaysleep 5 halfdim 1
/usr/bin/pmset -c sleep 0 disksleep 0 displaysleep 30 halfdim 1
else
/usr/bin/pmset sleep 0 disksleep 0 displaysleep 30 halfdim 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment