Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Last active December 19, 2023 14:38
Show Gist options
  • Save mschmitt/5fbbe043ba0f0e1f39ea517f1aae85ab to your computer and use it in GitHub Desktop.
Save mschmitt/5fbbe043ba0f0e1f39ea517f1aae85ab to your computer and use it in GitHub Desktop.
Gnome wallpaper changer in native systemd user units
#!/usr/bin/env ansible-playbook
---
- hosts: localhost
become: false
gather_facts: false
connection: local
tasks:
- name: Systemd user config location
file:
path: ~/.config/systemd/user/
state: directory
- name: Wallpaper service
copy:
src: wallpaper.service
dest: ~/.config/systemd/user/
- name: Wallpaper timer
copy:
src: wallpaper.timer
dest: ~/.config/systemd/user/
- name: Enable wallpaper timer
systemd:
name: wallpaper.timer
scope: user
enabled: yes
state: started
# vim: filetype=yaml
# ~/.config/systemd/user/wallpaper.service
[Unit]
Description=Wallpaper Change
StartLimitIntervalSec=0
[Service]
Type=oneshot
Environment=wpdir=%h/Nextcloud/Wallpapers
ExecStart=/usr/bin/env sh -c 'gsettings set org.gnome.desktop.background picture-uri "file://$(find "${wpdir}" -type f | shuf | head -1)"'
ExecStart=/usr/bin/env sh -c 'gsettings set org.gnome.desktop.background picture-uri-dark "$(gsettings get org.gnome.desktop.background picture-uri)"'
ExecStartPost=/usr/bin/env gsettings get org.gnome.desktop.background picture-uri
# ~/.config/systemd/user/wallpaper.timer
[Unit]
Description=Wallpaper Change Timer
[Timer]
OnStartupSec=60
OnUnitInactiveSec=900
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment