Guest User

Untitled

a guest
Oct 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. set_mode() {
  5. if [[ "$1" == "dark" ]]; then
  6. osascript -e '
  7. tell application id "com.apple.systemevents"
  8. tell appearance preferences
  9. if dark mode is false then
  10. set dark mode to true
  11. end if
  12. end tell
  13. end tell
  14. '
  15. elif [[ "$1" == "light" ]]; then
  16. osascript -e '
  17. tell application id "com.apple.systemevents"
  18. tell appearance preferences
  19. if dark mode is true then
  20. set dark mode to false
  21. end if
  22. end tell
  23. end tell
  24. '
  25. fi
  26. }
  27.  
  28.  
  29. next_sunrise=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunrise | cut -d \" -f2)
  30. next_sunset=$(/usr/bin/corebrightnessdiag nightshift-internal | grep nextSunset | cut -d \" -f2)
  31.  
  32. sunrise_hour=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunrise" +"%-H")
  33. sunrise_minute=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunrise" +"%-M")
  34.  
  35. sunset_hour=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunset" +"%-H")
  36. sunset_minute=$(date -jf "%Y-%m-%d %H:%M:%S %z" "$next_sunset" +"%-M")
  37.  
  38. current_hour=$(date +"%-H")
  39. current_minute=$(date +"%-M")
  40.  
  41.  
  42. # TESTING
  43. # echo "Alba: $sunrise_hour:$sunrise_minute – Tramonto: $sunset_hour:$sunset_minute"
  44. # read -p "Ora attuale: " current_hour
  45. # read -p "Minuto attuale: " current_minute
  46.  
  47.  
  48. if [[ "$current_hour" -gt "$sunrise_hour" ]] && [[ "$current_hour" -lt "$sunset_hour" ]]; then
  49. set_mode "light"
  50. elif [[ "$current_hour" == "$sunrise_hour" ]]; then
  51. if [[ "$current_minute" -ge "$sunrise_minute" ]]; then
  52. set_mode "light"
  53. else
  54. set_mode "dark"
  55. fi
  56. elif [[ "$current_hour" == "$sunset_hour" ]]; then
  57. if [[ "$current_minute" -ge "$sunset_minute" ]]; then
  58. set_mode "dark"
  59. else
  60. set_mode "light"
  61. fi
  62. else
  63. set_mode "dark"
  64. fi
Add Comment
Please, Sign In to add comment