Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save riseandshinefilms-admin/6ff0026c5b4725b7f56925d057ef0f01 to your computer and use it in GitHub Desktop.
Save riseandshinefilms-admin/6ff0026c5b4725b7f56925d057ef0f01 to your computer and use it in GitHub Desktop.
Bash script to enable/disable night shift on Mac OS
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 [enable|disable]"
exit 1
fi
plistLoc="/private/var/root/Library/Preferences/com.apple.CoreBrightness.plist"
currentUserUID=$(dscl . -read /Users/$(whoami)/ GeneratedUID) # Get the GeneratedUID for the current user
currentUserUID=$(echo $currentUserUID | cut -d' ' -f2) # Remove the "GeneratedUID: " part
currentUserUID="CBUser-"$currentUserUID # Append the prefix
# Enable settings
algoOverride=4
enabled=1
if [[ $1 == "disable" ]]; then
# Disable settings
algoOverride=3
enabled=0
fi
# Change the settings directly in the core brightness plist (defaults doesn't deal with nested data structures well)
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueLightReductionAlgoOverride $algoOverride" $plistLoc
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueReductionEnabled $enabled" $plistLoc
sudo /usr/libexec/PlistBuddy -c "Set :$currentUserUID:CBBlueReductionStatus:BlueLightReductionAlgoOverrideTimestamp `date`" $plistLoc
sudo killall cfprefsd
sudo killall corebrightnessd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment