Skip to content

Instantly share code, notes, and snippets.

@adamsdesk
Last active February 6, 2018 13:35
Show Gist options
  • Save adamsdesk/188090894884cf55a5b1 to your computer and use it in GitHub Desktop.
Save adamsdesk/188090894884cf55a5b1 to your computer and use it in GitHub Desktop.
Rotate the Gnome desktop wallpaper using Systemd user unit and timer.

Rotate Gnome Wallpaper using Systemd

  • Note: Adjust paths as applicable to the desired OS.
  • Note: The "$" represents the terminal prompt.
  • Note: The "#" represents the terminal prompt with elevated privleges.
  • Note: Verified to work on Arch Linux with Gnome v3.14 to v3.22.

Installation Instructions

  1. Download "gnome-rotate-wallpaper.service", "gnome-rotate-wallpaper.timer" and "gnome_rotate_wallpaper".
  2. Move the 2 files to where Systemd user files are stored.
# mv gnome-rotate-wallpaper.service gnome-rotate-wallpaper.timer /etc/systemd/user/
  1. Move the BASH script "gnome_rotate_wallpaper".
# mv gnome_rotate_wallpaper /usr/local/bin/
  1. Set execute permissions.
# chmod +x /usr/local/bin/gnome_rotate_wallpaper
  1. Enable the timer.
$ systemctl --user enable gnome-rotate-wallpaper.timer
  1. Verify the timer is enabled.
$ systemctl --user list-unit-files
gnome-rotate-wallpaper.service disabled
gnome-rotate-wallpaper.timer   enabled 
2 unit files listed.
  1. Start the timer.
# systemctl --user start gnome-rotate-wallpaper.timer
  1. Verify the timer has been started.
$ systemctl --user list-timers
NEXT                         LEFT    LAST                         PASSED UNIT                         ACTIVATES
Thu 2016-03-10 18:49:00 CST  1s left Thu 2016-03-10 18:48:56 CST  1s ago gnome-rotate-wallpaper.timer gnome-rotate-wallpaper.service
1 timers listed.
Pass --all to see loaded but inactive timers, too.

User Configuration

Change the default wallpaper directory.

  1. Create the required directories.
$ mkdir  ~/.config/systemd ~/.config/systemd/user
  1. Create the configuration file. Replace "username" with applicable value.
$ nano ~/.config/systemd/user/gnome-rotate-wallpaper.conf
WALLPAPER_DIR=/home/username/Pictures/wallpaper

Set the Interval to When the Wallpaper Changes.

Create the timer file and then change the "OnCalendar" value to the desired interval. Refer to ArchLinux: systemd/Timers for further details.

  1. Create the required directories.
$ mkdir  ~/.config/systemd ~/.config/systemd/user
  1. Create the configuration file.
$ nano ~/.config/systemd/user/gnome-rotate-wallpaper.timer
[Unit]
Description=Gnome rotate wallpaper

[Timer]
OnCalendar=*:0/1
Persistent=true
Unit=gnome-rotate-wallpaper.service

[Install]
WantedBy=gnome-rotate-wallpaper.service

External Links

[Unit]
Description=Gnome rotate wallpaper
[Service]
Type=oneshot
Environment=DISPLAY=:0
Environment=WALLPAPER_DIR=%h/Pictures/wallpaper
EnvironmentFile=-%h/.config/systemd/user/gnome-rotate-wallpaper.conf
ExecStart=/bin/bash /usr/local/bin/gnome_rotate_wallpaper
[Install]
WantedBy=default.target
[Unit]
Description=Gnome rotate wallpaper
[Timer]
OnCalendar=*:0/1
Persistent=true
Unit=gnome-rotate-wallpaper.service
[Install]
WantedBy=default.target
#!/bin/bash
selection=$(find $WALLPAPER_DIR -type f -name "*.jpg" -o -name "*.png" | shuf -n1)
gsettings set org.gnome.desktop.background picture-uri "file://$selection"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment