From b93770a3640c8bdcc32259abd9ab76cfb83b0355 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Sun, 30 Jul 2017 20:51:07 -0400 Subject: [PATCH] Add my little wallpaper/theme switcher Uses systemd timers to automatically change the wallpaper and switch my Xresources themes between light and dark modes at 7am and 9pm. --- wp/.config/systemd/user/wp.service | 6 ++++ wp/.config/systemd/user/wp.timer | 10 +++++++ wp/.local/bin/wp | 15 ++++++++++ wp/.local/bin/wp-auto | 48 ++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 wp/.config/systemd/user/wp.service create mode 100644 wp/.config/systemd/user/wp.timer create mode 100755 wp/.local/bin/wp create mode 100755 wp/.local/bin/wp-auto diff --git a/wp/.config/systemd/user/wp.service b/wp/.config/systemd/user/wp.service new file mode 100644 index 0000000..4308f83 --- /dev/null +++ b/wp/.config/systemd/user/wp.service @@ -0,0 +1,6 @@ +[Unit] +Description=wallpaper service + +[Service] +Type=oneshot +ExecStart=/usr/bin/bash -c %h/.local/bin/wp-auto diff --git a/wp/.config/systemd/user/wp.timer b/wp/.config/systemd/user/wp.timer new file mode 100644 index 0000000..448ab84 --- /dev/null +++ b/wp/.config/systemd/user/wp.timer @@ -0,0 +1,10 @@ +[Unit] +Description=wallpaper timer + +[Timer] +OnCalendar=07,21:00 +Unit=wp.service +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/wp/.local/bin/wp b/wp/.local/bin/wp new file mode 100755 index 0000000..9bfbd51 --- /dev/null +++ b/wp/.local/bin/wp @@ -0,0 +1,15 @@ +#! /bin/bash + +export DISPLAY=:0 + +case "$1" in + "day") + feh --bg-scale $HOME/usr/pics/island_day_by_arsenixc-d6ctqon.jpg + ;; + "night") + feh --bg-scale $HOME/usr/pics/island_night_by_arsenixc-d6cz757.jpg + ;; + *) + echo $"Usage: $0 {day|night}" + exit 1 +esac diff --git a/wp/.local/bin/wp-auto b/wp/.local/bin/wp-auto new file mode 100755 index 0000000..d5eeb12 --- /dev/null +++ b/wp/.local/bin/wp-auto @@ -0,0 +1,48 @@ +#! /bin/bash + +SED=$(which sed) +ROFI=$(which rofi) + +export DISPLAY=:0 +HOUR=$(date +%H) + +if [ -z "${SED}" ] +then + echo "Did not find 'sed', script cannot continue." + exit 1 +fi +if [ -z "${ROFI}" ] +then + echo "Did not find rofi, there is no point to continue." + exit 1 +fi + +### +# Create if not exists, then removes #include of .theme file (if present) and add the selected theme to the end. +# Repeated calls should leave the config clean-ish +### +function set_theme() +{ + CDIR="${HOME}/.config/rofi/" + if [ ! -d "${CDIR}" ] + then + mkdir -p ${CDIR} + fi + if [ -f "${CDIR}/config" ] + then + ${SED} -i "/rofi\.theme: .*\.rasi$/d" "${CDIR}/config" + fi + echo "rofi.theme: ${1}" >> "${CDIR}/config" + +} + +if [ "$HOUR" -gt "19" ] || [ "$HOUR" -lt "7" ] + then + feh --bg-scale $HOME/usr/pics/island_night_by_arsenixc-d6cz757.jpg + xrdb -merge $HOME/.Xresources.d/gruvbox-dark.xresources + set_theme "/usr/share/rofi/themes//gruvbox-dark.rasi" + else + feh --bg-scale $HOME/usr/pics/island_day_by_arsenixc-d6ctqon.jpg + xrdb -merge $HOME/.Xresources.d/gruvbox-light.xresources + set_theme "/usr/share/rofi/themes//gruvbox-light.rasi" +fi -- 2.20.1