Skip to content

Instantly share code, notes, and snippets.

@bb441db
Last active April 29, 2022 10:03
Show Gist options
  • Save bb441db/c2c3066eb10a60c8edb9449f86870285 to your computer and use it in GitHub Desktop.
Save bb441db/c2c3066eb10a60c8edb9449f86870285 to your computer and use it in GitHub Desktop.
Ubuntu 22.04 automatically update color scheme preference at night

Place the .timer and .service file in ~/.config/systemd/user

Place the update-color-scheme file somewhere in $PATH

Enable and start the timer

systemctl --user enable update-color-scheme-preference.timer
systemctl --user start update-color-scheme-preference.timer
#!/bin/bash
if ! [ -x "$(command -v date)" ]; then
echo "date is not installed" &>2
fi
if ! [ -x "$(command -v gsettings)" ]; then
echo "gsettings is not installed" &>2
fi
TIME=$(date +"%H:%M:%S")
# Light mode turns on at 09:00 ends at 20:00
SCHEDULE=("09:00:00" "20:00:00")
PREFERENCE="dark"
if [[ "$TIME" > "${SCHEDULE[0]}" && "$TIME" < "${SCHEDULE[1]}" ]]; then
PREFERENCE="light"
fi
gsettings set org.gnome.desktop.interface color-scheme "prefer-${PREFERENCE}"
[Unit]
Description=Updates Prefered Color Scheme
[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=update-color-scheme
[Install]
WantedBy=basic.target
[Unit]
Description=Update Prefered Color Scheme Timer
[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true
Unit=update-color-scheme-preference.service
[Install]
WantedBy=update-color-scheme-preference.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment