-
-
Save riseandshinefilms-admin/6ff0026c5b4725b7f56925d057ef0f01 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