0

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.

8
  • What will your unit timer do? Will it run some GUI app when the graphical session is ready? Nov 29, 2022 at 4:20
  • It runs a bash script which changes my wallpaper once per hour, with some bells and whistles, using feh. Nov 29, 2022 at 6:13
  • Can you add to your question the content of your bash script? Also, you have the systemd timer, it's ok, but do you have the systemd service too? (systemd timers must trigger a systemd service). If you do, then please provide what you have in the systemd service. Nov 29, 2022 at 6:29
  • There is a service. It all works fine if I start the timer manually (I probably should have mentioned that), the problem is just that it won't start on its own. I don't see how the content of the service or the script would effect that but I'll add them to my question in a second. Nov 29, 2022 at 6:44
  • Oh! I think your main problem is that you have not enabled your systemd timer. Try this: sudo systemctl enable your_timer.timer. When you restart your machine the timer should be active (and maybe ready and waiting for triggering your systemd service) Nov 29, 2022 at 6:54

1 Answer 1

1

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.

It does – the .target needs to be explicitly started by your ~/.xinitrc (or by your WM's "autostart").

graphical-session.target is not started automatically by Xorg for every GUI session, only pulled in as a dependency in specific situations (such as by gnome-session.target, as GNOME primarily uses systemd for session management).

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .