You are not logged in.

#1 2013-01-03 00:28:58

0112358
Member
Registered: 2012-04-09
Posts: 38

[Solved] Match random wallpaper between Slim and Desktop

I'd like Slim and my desktop (Xmonad) to have the same wallpaper, randomly selected from a specific directory each time I boot.  The way I've thought to do this is:

1. Before Slim starts, run a script to
    a. choose a random file from /home/wallpapers
    b. copy the file as /tmp/wallpaper.jpg

2. link Slim's default background to /tmp/wallpaper.jpg

3. set /tmp/wallpaper.jpg as the background with feh in .xinitrc

I am having trouble with part 1.  I don't know how to run a script before Slim starts, and I don't quite know how to get a script to copy a file from one directory to another with a new name.

Could anyone help?  Or suggest an easier way to do this?  Thanks.

Last edited by 0112358 (2013-01-03 17:15:58)

Offline

#2 2013-01-03 03:39:35

WizenedEE
Member
Registered: 2012-03-14
Posts: 8

Re: [Solved] Match random wallpaper between Slim and Desktop

you'll want to create a systemd service file. It sounds to me like the type should be oneshot and should have before=slim.service. the ExecStart line could be something like

/bin/bash -c 'cp $(find /home/wallpaper | sort -R | head -n 1) /tmp/wallpaper'

EDIT: even better, replace cp with ln -s to get a symbolic link rather than a physical copy.

Last edited by WizenedEE (2013-01-03 03:42:04)

Offline

#3 2013-01-03 05:35:59

0112358
Member
Registered: 2012-04-09
Posts: 38

Re: [Solved] Match random wallpaper between Slim and Desktop

Thanks.  I'm having trouble with the service file though - I haven't gotten the knack of these yet.  When I save the below as /etc/systemd/system/wallpaper.service and test it with systemctl start wallpaper.service, it just hangs.  Any idea what I'm messing up?


[Unit]
Description=Sync wallpaper between Slim and Desktop
Before=slim.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'ln -s $(find ~/Pictures/other/wallpapers/favorites | sort -R | head -n 1) /tmp/wallpaper.jpg'

[Install]
WantedBy=multi-user.target

Offline

#4 2013-01-03 08:08:58

heman
Banned
Registered: 2012-12-02
Posts: 14

Re: [Solved] Match random wallpaper between Slim and Desktop

You might be better off turning your command into a small script and running it from service file. Using full path to wallpapers as well

Last edited by heman (2013-01-03 09:14:11)

Offline

#5 2013-01-03 11:24:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: [Solved] Match random wallpaper between Slim and Desktop

And/or include "User=<yourusername>" because, as written, the ~ will be expanded to /root/.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2013-01-03 17:19:31

0112358
Member
Registered: 2012-04-09
Posts: 38

Re: [Solved] Match random wallpaper between Slim and Desktop

Got it.  Thanks everyone.  Using the full path and putting the command in a script worked.  The working file is below.

[Unit]
Description=Sync wallpaper between Slim and desktop
Before=slim.service

[Service]
Type=oneshot
ExecStart=/home/USER/Scripts/wallpaper.sh

[Install]
WantedBy=multi-user.target

Offline

Board footer

Powered by FluxBB