Created
April 3, 2017 18:40
-
-
Save thomasfinch/14bd3181799734c872d2ad3b207cc01c to your computer and use it in GitHub Desktop.
Bash script to enable/disable night shift on Mac OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
This is not working for me on 10.12.6.