Skip to content

Instantly share code, notes, and snippets.

@thomasfinch
Created April 3, 2017 18:40
Show Gist options
  • Save thomasfinch/14bd3181799734c872d2ad3b207cc01c to your computer and use it in GitHub Desktop.
Save thomasfinch/14bd3181799734c872d2ad3b207cc01c 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
@dzg
Copy link

dzg commented Jan 13, 2018

This is not working for me on 10.12.6.

File Doesn't Exist, Will Create: /private/var/root/Library/Preferences/com.apple.CoreBrightness.plist
Set: Entry, ":CBUser-xxx:CBBlueReductionStatus:BlueLightReductionAlgoOverride", Does Not Exist
Set: Entry, ":CBUser-xxx:CBBlueReductionStatus:BlueReductionEnabled", Does Not Exist
Set: Entry, ":CBUser-xxx:CBBlueReductionStatus:BlueLightReductionAlgoOverrideTimestamp", Does Not Exist

@ikuwow
Copy link

ikuwow commented Sep 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment