Skip to content

Instantly share code, notes, and snippets.

@AKST
Last active June 24, 2019 12:40
Show Gist options
  • Save AKST/c1ab8aa2110a018d57e4088b2b11cdfc to your computer and use it in GitHub Desktop.
Save AKST/c1ab8aa2110a018d57e4088b2b11cdfc to your computer and use it in GitHub Desktop.
I wrote a some fish shell that updates the operating systems appearance to use light mode during the day and dark mode during the evening.
#!/usr/bin/env fish
begin
function current_appearance
set output (osascript -l JavaScript -e "
Application('System Events').appearancePreferences.darkMode()
")
if test "$output" = "true"
echo "dark"
else
echo "light"
end
end
# Originally the apple script for logging the notification
# was seperate from updating whether dark mode was active.
# But there was a bug with the appearance not updating, without
# running it twice.
function update_with_applescript
set mode $argv[1]
set title $argv[2]
set message $argv[3]
if [ "$mode" = "dark" ]
set is_dark "true"
else
set is_dark "false"
end
osascript -e "
tell application \"System Events\"
tell appearance preferences
set dark mode to $is_dark
end tell
end tell
display notification \"$message\" with title \"$title\"
"
end
set hour (date +"%H")
set mode (current_appearance)
if [ $hour -ge 6 ] && [ $hour -lt 17 ] && [ $mode = "dark" ]
update_with_applescript light "The sun is out!" "Set OS appearance to light mode."
else if [ $hour -lt 6 -o $hour -ge 17 ] && [ $mode = "light" ]
update_with_applescript dark "It's starting to get dark" "Set OS appearance to dark mode."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment