我正在尝试使用 systemd 计时器来更改我的背景壁纸,但它似乎没有达到我想要的效果。
下面我列出了我拥有的相关文件和输出。
bgchange.计时器
[Unit]
Description=Timer for background change
[Timer]
OnUnitActiveSec=10sec
OnActiveSec=5sec
OnBootSec=1sec
Persistent=true
[Install]
WantedBy=timers.target
bgchange.service
[Unit]
Description=Change background image periodically
[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/home/emobe/scripts/changebg.sh
/home/emobe/scripts/changebg.sh
#!/bin/bash
feh --no-fehbg --bg-scale --randomize /home/emobe/Pictures/wallpapers/*
bgchange.计时器状态
● bgchange.timer - Timer for background change
Loaded: loaded (/etc/systemd/system/bgchange.timer; enabled; preset: disabled)
Active: active (waiting) since Fri 2023-01-06 09:33:44 GMT; 4h 12min ago
Until: Fri 2023-01-06 09:33:44 GMT; 4h 12min ago
Trigger: Fri 2023-01-06 13:46:24 GMT; 4s left
Triggers: ● bgchange.service
systemctl 列表定时器
Fri 2023-01-06 17:39:24 GMT 3h 52min left Thu 2023-01-05 23:57:47 GMT 13h ago updatedb.timer updatedb.service
Sat 2023-01-07 00:00:00 GMT 10h left Fri 2023-01-06 00:00:01 GMT 13h ago logrotate.timer logrotate.service
Sat 2023-01-07 00:00:00 GMT 10h left Fri 2023-01-06 00:00:01 GMT 13h ago shadow.timer shadow.service
Sat 2023-01-07 09:48:44 GMT 20h left Fri 2023-01-06 09:48:44 GMT 3h 58min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Sat 2023-01-07 09:54:52 GMT 20h left Fri 2023-01-06 00:34:15 GMT 13h ago man-db.timer man-db.service
Sat 2023-01-07 15:00:00 GMT 1 day 1h left Tue 2022-12-06 22:57:11 GMT 1 month 0 days ago pamac-cleancache.timer pamac-cleancache.service
Thu 2023-01-12 08:45:44 GMT 5 days left Thu 2023-01-05 23:57:47 GMT 13h ago pamac-mirrorlist.timer pamac-mirrorlist.service
Thu 2023-01-12 20:26:18 GMT 6 days left Fri 2023-01-06 00:25:48 GMT 13h ago archlinux-keyring-wkd-sync.timer archlinux-keyring-wkd-sync.service
- - Fri 2023-01-06 13:46:53 GMT 74ms ago bgchange.timer bgchange.service
答案1
DISPLAY
您应该将它们作为用户服务/计时器运行...然后您就不需要在服务文件中设置,例如
[Unit]
Description=Change background image periodically
[Service]
ExecStart=/home/emobe/scripts/changebg.sh
应该足够了。systemd
通常会放入用户文件~/.config/systemd/user/
,因此请将它们放在那里
~/.config/systemd/user/bgchange.timer
~/.config/systemd/user/bgchange.service
然后以普通用户身份运行
systemctl --user daemon-reload
systemctl --user enable --now bgchange.timer
检查计时器是否处于活动状态,始终为--user
:
systemctl --user list-timers