How to run systemd service every hour but also everytime user logs in?

What I want:
I am trying to write a systemd service/timer that changes wallpaper every hour. But it should also set the wallpaper on the login.

System Info:
WM: OpenBox
DM: LightDM
Wallpaper App: Nitrogen

What I tried:

# rand-wall.service 

[Unit]
Description=Sets the desktop wallpaper in random

[Service]
Type=oneshot
ExecStart=/usr/bin/nitrogen --set-zoom-fill --random '/path/to/wallpapers/'

# rand-wall.timer

[Unit]
Description=Sets the desktop background randomly - timer

[Timer]
OnStartupSec=1s
OnCalendar=hourly

[Install]
WantedBy=timers.target

Outcome:

While the wallpaper is changing hourly, I cannot figure out how to make it run every time I login (when I logout and then login). So until 1 hour passes the desktop background stays “grey”.

Also, how can I change the wallpaper of the login screen?

Hi
nitrogen has own settings, It can change wallpaper all on its own at startup,
if set up that way.

I know another distro that uses this option, I uninstall it as I hate change.

HIH

–
Data

1 Like

There is also variety a wallpaper changer, it is in the repos (or aur can’t remember :smiley: ).

1 Like

In community repo.

1 Like

At work :smiley: Lovely Windows 10, it is PITA pleasure to use :rofl:

1 Like

Though there might be a way to get it done the way you want with services and timers, you could execute that command line at openbox startup:

http://openbox.org/wiki/Help:Autostart
https://wiki.archlinux.org/title/Openbox#Autostart

and then let the timer to take care of running it at hourly basis.

1 Like

For just in case…

https://f-droid.org/en/packages/com.rascarlo.arch.packages/

1 Like

@chromian
If I understand your question correctly, you could use additional setting

[Timer]
Persistent=true
# ...

EDIT: just noticed that this might not be what you wanted.
Anyway, try these commands:

man systemd.timer
man systemd.time

EDIT2: another way to run stuff at login is to write an autostart file into folder /etc/xdg/autostart. They are traditional .desktop files that run at login. I think @pebcak already was going this way. :wink:

2 Likes

Thank you pebcak and manuel for your guidance. I suspected as much that I am gonna need the autostart file of openbox. That is how EndeavourOS/Openbox “restores” the wallpaper when the user logs in. It’s just that I wanted all the “config” for the wallpaper setup to be at one place but anyway this is what I ended up doing:

The rand-wall service and timer files are as they are in ~/.config/systemd/user. I enable the timer with systemctl --user enable --now rand-wall.timer. It will take care of changing the wallpaper every hour.

Now for setting the wallpaper every time I log in, I go to ~/.config/openbox/ and edit the autostart file as:

# Wallpaper
# nitrogen --restore &
nitrogen --set-zoom-fill --random '/path/to/wallpapers/' &

Now,

  1. A random wallpaper is set every time I log in.
  2. A random wallpaper is set every 1 hour.

I am actually a long time user of variety and I love it. I am looking for something light… that is all.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.