Created
October 21, 2018 17:43
-
-
Save jacopo-j/506231d8ea2ba55af8b92f63dfdda879 to your computer and use it in GitHub Desktop.
macOS Mojave auto dark mode
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 | |
set_mode() { | |
if [[ "$1" == "dark" ]]; then | |
osascript -e ' | |
tell application id "com.apple.systemevents" | |
tell appearance preferences | |
if dark mode is false then | |
set dark mode to true | |
end if | |
end tell | |
end tell | |
' | |
elif [[ "$1" == "light" ]]; then | |
osascript -e ' | |
tell application id "com.apple.systemevents" | |
tell appearance preferences | |
if dark mode is true then | |
set dark mode to false | |
end if | |
end tell | |
end tell | |
' | |
fi | |
} | |
next_sunrise=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunrise | cut -d \" -f2) | |
next_sunset=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunset | cut -d \" -f2) | |
sunrise_hour=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunrise" +"%-H") | |
sunrise_minute=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunrise" +"%-M") | |
sunset_hour=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunset" +"%-H") | |
sunset_minute=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunset" +"%-M") | |
current_hour=$(date +"%-H") | |
current_minute=$(date +"%-M") | |
# TESTING | |
# echo "Alba: $sunrise_hour:$sunrise_minute – Tramonto: $sunset_hour:$sunset_minute" | |
# read -p "Ora attuale: " current_hour | |
# read -p "Minuto attuale: " current_minute | |
if [[ "$current_hour" -gt "$sunrise_hour" ]] && [[ "$current_hour" -lt "$sunset_hour" ]]; then | |
set_mode "light" | |
elif [[ "$current_hour" == "$sunrise_hour" ]]; then | |
if [[ "$current_minute" -ge "$sunrise_minute" ]]; then | |
set_mode "light" | |
else | |
set_mode "dark" | |
fi | |
elif [[ "$current_hour" == "$sunset_hour" ]]; then | |
if [[ "$current_minute" -ge "$sunset_minute" ]]; then | |
set_mode "dark" | |
else | |
set_mode "light" | |
fi | |
else | |
set_mode "dark" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment