I am a new user of swaywm and fairly new with creating my own custom systemd services. I previously used Openbox, feh and systemd to created a scripted wallpaper change every 30 min. The below is a foo.service which functions fine in openbox:
[Unit]
Description=wallpaper rotate service
RefuseManualStart=no
RefuseManualStop=no
[Service]
Type=oneshot
User=trentonknight
ExecStart=/bin/sh -c 'DISPLAY=:0.0 feh --recursive --randomize --bg-fill /home/trentonknight/Pictures/Wallpaper/*'
This is the timer which runs it every 30 min:
[Unit]
Description=wallpaper rotate timer
RefuseManualStart=no
RefuseManualStop=no
[Timer]
Persistent=false
OnCalendar=*:0/30
Unit=wrotate.service
[Install]
WantedBy=default.target
Swaywm uses the Wayland compositer and is fantastic. However, feh only works with X. Without feh I can easily change my wallpaper with this simple command native to swaywm:
swaymsg output DP-3 bg foo_background.png
DP-3 is a result of runing this command prior:
swaymsg -t get_outputs
Using the above output command in a bash script I can automate the random selection of images for wallpapers in a directory. This works when run from command line without an issue:
#!/bin/bash
NEW=$(ls ~/Pictures/Wallpaper/ | shuf -n 1)
NEW_SWAY_BACK="~/Pictures/Wallpaper/"$NEW
swaymsg output DP-3 bg $NEW_SWAY_BACK fill
However, if I attempt to call this bash script from the following custom service it fails. Here is the service first:
[Unit]
Description=swaymsg output rotate wallpaper service
RefuseManualStart=no
RefuseManualStop=no
[Service]
WorkingDirectory=/usr/share/backgrounds/sway/
Type=forking
User=trentonknight
ExecStart=/usr/bin/bash sway_backgroud_changer.sh
KillMode=process
This is one of many versions I have attempted but they all have the same status after atempting to start:
[trentonknight@archboX system]$ sudo systemctl status swaywallr.service
* swaywallr.service - swaymsg output rotate wallpaper service
Loaded: loaded (/etc/systemd/system/swaywallr.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2018-05-12 18:37:17 EDT; 5s ago
Process: 30491 ExecStart=/usr/bin/bash sway_backgroud_changer.sh (code=exited, status=1/FAILURE)
May 12 18:37:17 archboX systemd[1]: Starting swaymsg output rotate wallpaper service...
May 12 18:37:17 archboX bash[30491]: sway socket not detected.
May 12 18:37:17 archboX bash[30491]: E: 05/12/18 18:37:17 - [ipc-client.c:37] Unable to connect to
May 12 18:37:17 archboX systemd[1]: swaywallr.service: Control process exited, code=exited status=1
May 12 18:37:17 archboX systemd[1]: swaywallr.service: Failed with result 'exit-code'.
May 12 18:37:17 archboX systemd[1]: Failed to start swaymsg output rotate wallpaper service.
[Install]
WantedBy=multi-user.target
I see that the SWAYSOCK is as follows:
[trentonknight@archboX system]$ echo $SWAYSOCK
/run/user/1000/sway-ipc.1000.527.sock
I'm clueless how to call it properly. Or even if that the problem? Additionally, I am running the following:
[trentonknight@archboX system]$ uname -a
Linux archboX 4.16.8-1-ARCH #1 SMP PREEMPT Wed May 9 11:25:02 UTC 2018 x86_64 GNU/Linux
I'm open to alternative approaches as well. I see there is a swaybg but running give the following printout and the man page does not include swaybg at all:
[trentonknight@archboX sway]$ swaybg
05/12/18 18:43:26 - [main.c:63] Do not run this program manually. See man 5 sway and look for output options.
My guess is its still in development.
Thanks to the guys and girls at #sway on freenode I was able to fix this issue by simply using:
systemctl --user
I did not realize that user level service was separate from system services. In the end my script is extremely basic running from:
.config/systemd/user/
I did have to append:
systemctl --user import-environment
to my .bashrc temporarily until I can analyze what PATH is missing. Regardless, if you run into a similar circumstance check out:
https://wiki.archlinux.org/index.php/Systemd/User
If anyone is interested in auto changing thier desktop wallpaper in sway the following should work. Create the following directory and files, name as you see fit with the services of course:
mkdir -p ~/.config/systemd/user
touch ~/.config/systemd/user/foo.service
touch ~/.config/systemd/user/foo.timer
foo.service
[Unit]
Description=swaymsg output rotate wallpaper service
[Service]
ExecStart=/usr/share/backgrounds/sway/sway_backgroud_changer.sh
[Install]
WantedBy=multi-user.target
foo.timer set the time to whatever you want. The below is 59 min.
[Unit]
Description=wallpaper rotate timer
RefuseManualStart=no
RefuseManualStop=no
[Timer]
Persistent=false
OnCalendar=*:0/59
Unit=foo.service
[Install]
WantedBy=default.target
Bash script for rotating wallpaper:
[trentonknight@archboX user]$ cat /usr/share/background/sway/sway_backgroud_changer.sh
#!/bin/bash
NEW=$(ls ~/Pictures/Wallpaper/ | shuf -n 1)
NEW_SWAY_BACK="~/Pictures/Wallpaper/"$NEW
swaymsg -s $SWAYSOCK output DP-3 bg $NEW_SWAY_BACK fill
I have not determined a better way to ensure PATHS are set prior to this service running, at least tonight so append this to your .bashrc or use the Arch linux tutorial to improve on it:
[trentonknight@archboX ~]$ cat .bashrc
systemctl --user import-environment
Run to enable before next login:
systemctl --user enable foo.timer
If you want to test before the timer:
systemctl --user start foo.service
One last thing. Make sure you have some quality images in ~/Pictures/Wallpaper or where ever you edited the PATH to for loading images from. DP-3 was my output verify your using:
swaymsg -t get_outputs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With