Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment