I currently have this timer:
[Unit]
Description=Schedule wallpaper rotation
[Timer]
OnCalendar=*-*-* *:00:00
Persistent=true
[Install]
WantedBy=graphical-session.target
Which runs this service:
[Unit]
Description=Rotate wallpapers
[Service]
Type=oneshot
ExecStart=%h/bin/wpman %h/docs/media/wallpaper/arkady
Which runs this script:
#!/bin/bash
TARGET="${1}"
CURRENT=
NEXT=
REST=
LISTFILE="${HOME}/.wallpaper-list"
TARGFILE="${HOME}/.wallpaper-target"
WALLFILE="${HOME}/.wallpaper"
if [[ ! -d "${TARGET}" ]]; then
echo "Invalid target: '${TARGET}'"
exit 1
fi
TARGET="$(realpath "${TARGET}")"
[[ -f "${TARGFILE}" ]] && CURRENT="$(cat "${TARGFILE}")"
if [[ -f "${LISTFILE}" ]]; then
NEXT="$(head -n 1 "${LISTFILE}")"
REST="$(tail -n +2 "${LISTFILE}")"
fi
mklist() {
find "${TARGET}" -mindepth 1 -maxdepth 1 -type f | sort -R > "${LISTFILE}"
echo "${TARGET}" > "${TARGFILE}"
NEXT="$(head -n 1 "${LISTFILE}")"
REST="$(tail -n +2 "${LISTFILE}")"
}
set-wallpaper() {
feh --bg-fill "${NEXT}"
echo "${REST}" > "${LISTFILE}"
cp "${NEXT}" "${WALLFILE}"
}
if [[ -z "${CURRENT}" ]] || ([[ -n "${CURRENT}" ]] && [[ "${CURRENT}" != "${TARGET}" ]]) || [[ ! -f "${LISTFILE}" ]] || [[ -z "${NEXT}" ]]; then
mklist
fi
set-wallpaper
But it doesn't start. I thought about just starting it from timers.target and checking in my script if $DISPLAY is empty and exiting if so, but I'm not sure if $DISPLAY will be available to the script if started this way. FWIW, I'm not running any desktop environment, just X and a window manager. I'm not sure if that effects how graphical-session.target is triggered.
Is there a way to get this to work how I want? Maybe a systemd timer wasn't the best approach.